You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@zookeeper.apache.org by Yogesh Patil <pa...@gmail.com> on 2014/10/30 22:19:23 UTC
Command Line arguments for ZooKeeper Java example
Hi
I am first time ZooKeepe(ZK) user and trying my hands with the java example
that is provided.
If I understood the purpose of sample client application,
1. It subscribes to (Watches) server notifications
2. Writes to file if notification received
3. Starts/Stops executing the 'exec' commands given as 4th command line
argument
However I fail to test use it as I don't understand what should be the 3rd
run time argument to run this.
I used this - 127.0.0.1 test1 sample.txt ls -la commands line arguments and
I am getting following error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/slf4j/LoggerFactory
at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
at Executor.<init>(Executor.java:38)
at Executor.main(Executor.java:59)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
P.S. Codes for Executor and DataMonitor remains as it is given
Can someone help me run it using correct cmd line arguments ?
Thanks,
Yogesh Patil
Re: Command Line arguments for ZooKeeper Java example
Posted by Luke Stephenson <lu...@gmail.com>.
Hello,
Almost the same question was asked yesterday, so having a look at this
thread may help.
http://mail-archives.apache.org/mod_mbox/zookeeper-user/201410.mbox/%3CC143048FDA902A48AE0A6ABFA6D8E8D16886BE26@EXMBDB03.campus.ncl.ac.uk%3E
Make sure you have the slf4j dependency (I'd recommend using maven to
manage).
This was the response provided yesterday:
These are some examples of setting the class path in run time:
1- java -cp target/lib/*:target/*
edu.brown.cs.zkbenchmark.ZooKeeperBenchmark --conf benchmark.conf
2- java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
3- javac -classpath
./log4j-1.2.16.jar:./slf4j-api-1.6.1.jar:./slf4j-log4j12-1.6.1.jar
LearnerLeaderACK/*.java
java -cp .:./log4j-1.2.16.jar:./slf4j-api-1.6.1.jar:./slf4j-log4j12-1.6.1.jar
LearnerLeaderACK/StartLeader
Ibrahim
Hope that helps
Luke
On 31 October 2014 08:19, Yogesh Patil <pa...@gmail.com> wrote:
> Hi
>
> I am first time ZooKeepe(ZK) user and trying my hands with the java example
> that is provided.
>
> If I understood the purpose of sample client application,
> 1. It subscribes to (Watches) server notifications
> 2. Writes to file if notification received
> 3. Starts/Stops executing the 'exec' commands given as 4th command line
> argument
>
> However I fail to test use it as I don't understand what should be the 3rd
> run time argument to run this.
>
> I used this - 127.0.0.1 test1 sample.txt ls -la commands line arguments and
> I am getting following error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/slf4j/LoggerFactory
> at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
> at Executor.<init>(Executor.java:38)
> at Executor.main(Executor.java:59)
> Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
> at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> ... 3 more
>
> P.S. Codes for Executor and DataMonitor remains as it is given
>
>
> Can someone help me run it using correct cmd line arguments ?
>
>
>
> Thanks,
> Yogesh Patil
>
Re: Command Line arguments for ZooKeeper Java example
Posted by Wendy Smoak <ws...@gmail.com>.
On Sat, Nov 1, 2014 at 11:25 AM, Wendy Smoak <ws...@gmail.com> wrote:
> So that you can see the start, stop, and restart behavior, I updated
> this to use a trivial 'program' (bash script) that counts up 1, 2, 3,
> with a five second delay.
... and, here it is again with a Maven build:
https://github.com/wsmoak/zookeeper/tree/master/simple-watch-mvn
(If you're at a Windows command line, I imagine you'll need to give it
a different "program" to run as the bash script won't work. Change
the exec plugin config to do that, or ask if you get stuck.)
-Wendy
Re: Command Line arguments for ZooKeeper Java example
Posted by Wendy Smoak <ws...@gmail.com>.
So that you can see the start, stop, and restart behavior, I updated
this to use a trivial 'program' (bash script) that counts up 1, 2, 3,
with a five second delay.
https://github.com/wsmoak/zookeeper/tree/master/simple-watch
Here is what it might look like:
(In the command line interface)
[zk: localhost:2181(CONNECTED) 16] create /stuff my_data
Created /stuff
[zk: localhost:2181(CONNECTED) 17] set /stuff other_data
[zk: localhost:2181(CONNECTED) 18] delete /stuff
(running the watcher example)
2014-11-01 11:05:43,908 [myid:] - INFO
[main-SendThread(localhost:2181):ClientCnxn$SendThread@1346] - Session
establishment complete on server localhost/127.0.0.1:2181, sessionid =
0x1496bca44fe0002, negotiated timeout = 4000
Starting child
1
2
3
4
Stopping child
Starting child
1
2
3
Killing process
-Wendy
Re: Command Line arguments for ZooKeeper Java example
Posted by Wendy Smoak <ws...@gmail.com>.
If you look at
https://github.com/wsmoak/zookeeper/blob/master/simple-watch/run.sh
you can see the minimal set of things I had to add to the CLASSPATH.
zookeeper-3.5.0-alpha.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
log4j-1.2.16.jar
The logging jars were not needed to compile the project, but they are
needed to run it.
The next thing you might run into is a complaint about configuring
Log4j. There is a sample config file in the conf/ directory of the
ZooKeeper .tar.gz distribution.
-Wendy
Re:Re: Command Line arguments for ZooKeeper Java example
Posted by Tom <bi...@163.com>.
Have you added the slf4j on your classpath?
-Todd
At 2014-11-01 07:28:36, "Yogesh Patil" <pa...@gmail.com> wrote:
>Hi Wendy,
>thank you for taking an effort to try and making it work.
>
>As I tried earlier, I used eclipse IDE and gave following arguments in run
>config:
>localhost /stuff output.txt ls
>
>so encountered following error.
>
>Exception in thread "main" java.lang.NoClassDefFoundError:
>org/slf4j/LoggerFactory
>at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
>at Executor.<init>(Executor.java:38)
>at Executor.main(Executor.java:59)
>
>
>
>On Fri, Oct 31, 2014 at 7:13 PM, Wendy Smoak <ws...@gmail.com> wrote:
>
>> On Fri, Oct 31, 2014 at 3:02 PM, Wendy Smoak <ws...@gmail.com> wrote:
>>
>> > Is it this one? http://zookeeper.apache.org/doc/trunk/javaExample.html
>>
>> Assuming it was... have a look at this:
>>
>> https://github.com/wsmoak/zookeeper/tree/master/simple-watch
>>
>> I'm not entirely sure about a couple of things, but at least it runs
>> and behaves as described.
>>
>> Hope that helps! And just ask if something doesn't work or doesn't make
>> sense.
>>
>> -Wendy
>>
Re: Command Line arguments for ZooKeeper Java example
Posted by Yogesh Patil <pa...@gmail.com>.
Hi Wendy,
thank you for taking an effort to try and making it work.
As I tried earlier, I used eclipse IDE and gave following arguments in run
config:
localhost /stuff output.txt ls
so encountered following error.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/slf4j/LoggerFactory
at org.apache.zookeeper.ZooKeeper.<clinit>(ZooKeeper.java:94)
at Executor.<init>(Executor.java:38)
at Executor.main(Executor.java:59)
On Fri, Oct 31, 2014 at 7:13 PM, Wendy Smoak <ws...@gmail.com> wrote:
> On Fri, Oct 31, 2014 at 3:02 PM, Wendy Smoak <ws...@gmail.com> wrote:
>
> > Is it this one? http://zookeeper.apache.org/doc/trunk/javaExample.html
>
> Assuming it was... have a look at this:
>
> https://github.com/wsmoak/zookeeper/tree/master/simple-watch
>
> I'm not entirely sure about a couple of things, but at least it runs
> and behaves as described.
>
> Hope that helps! And just ask if something doesn't work or doesn't make
> sense.
>
> -Wendy
>
Re: Command Line arguments for ZooKeeper Java example
Posted by Wendy Smoak <ws...@gmail.com>.
On Fri, Oct 31, 2014 at 3:02 PM, Wendy Smoak <ws...@gmail.com> wrote:
> Is it this one? http://zookeeper.apache.org/doc/trunk/javaExample.html
Assuming it was... have a look at this:
https://github.com/wsmoak/zookeeper/tree/master/simple-watch
I'm not entirely sure about a couple of things, but at least it runs
and behaves as described.
Hope that helps! And just ask if something doesn't work or doesn't make sense.
-Wendy
Re: Command Line arguments for ZooKeeper Java example
Posted by Wendy Smoak <ws...@gmail.com>.
On Thu, Oct 30, 2014 at 5:19 PM, Yogesh Patil <pa...@gmail.com> wrote:
> I am first time ZooKeepe(ZK) user and trying my hands with the java example
> that is provided.
What example are you working with?
I've made it to
http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html#ch_programStructureWithExample
but the example mentioned there is TBD.
Is it this one? http://zookeeper.apache.org/doc/trunk/javaExample.html
If you describe what you've done so far (what files you put where, how
you're compiling, the exact command you issued to get that error,)
then someone can probably help you through it.
-Wendy