4

I downloaded the latest google caliper source code and build it using maven. Now I am trying to run google caliper example test given here.. I am using the below command to execute the test.

java -cp /home/rakesh/programming/refcode/caliper/caliper/target/caliper-1.0-SNAPSHOT.jar  com.google.caliper.Runner examples.StringBuilderBenchmark

But I get the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Splitter
    at com.google.caliper.Runner.<clinit>(Runner.java:67)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Splitter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

I tried to look into the caliper jar file and I couldn't find the com.google.common.base.Splitter class file. Even I coudln't get the Splitter.java file. Can any one suggest me what I am missing here?

EDIT1:
I figured out that com.google.common.base.Splitter class is present in appengine-tools-sdk-1.2.1.jar jar file I included the jar file in the command as shown below.

java -cp /home/rakesh/programming/refcode/caliper/caliper/target/caliper-1.0-SNAPSHOT.jar:/home/rakesh/programming/refcode/caliper/examples/appengine-tools-sdk-1.2.1.jar  com.google.caliper.Runner examples.StringBuilderBenchmark

But the error is same it doesn't look like the command is looking into the other jar file which has the Splitter class.

Rakesh
  • 3,987
  • 10
  • 43
  • 68
  • 2
    No idea about appengine, but `Splitter` is part of [Guava](http://code.google.com/p/guava-libraries). Concerning the command, you must be doing something wrong, as it has no choice but to use the provided CLASSPATH. Actually, maven should take care of everything... – maaartinus Aug 26 '12 at 12:38
  • If I use the provided command then also it doesn't work. Can you give me command example and in which directory I should run this command? – Rakesh Aug 26 '12 at 16:51

2 Answers2

1

My answer is no real answer, but it's too long for a comment.

Unfortunately, I know close to nothing about maven. What works for me is downloading the git repository and creating eclipse project. This is surely no clean solution, but it's easy and allows me to learn from the libraries.

What worked for me:

In my working tree I located pom.xml, switched to that directory and ran mvn install. It created some jar somewhere deep in ~/.m2/repository. As the path was too long for my patience, I created a symlink via ln -s ~/.m2/repository/com/google/ .. I compiled manually the StringBuilderBenchmark and got exactly your error.

Then I ran mvn install in my guava folder and now running

java -cp .:\
./google/caliper/caliper/1.0-SNAPSHOT/caliper-1.0-SNAPSHOT.jar:\
./google/guava/guava/12.0/guava-12.0.jar \
examples/StringBuilderBenchmark

complains about missing com/google/gson/JsonParser from gson. Then you may need google instrumenter and that's it.

This is surely not the way to go. Maven should take care of everything and I very much hope it can. I'd suggest adding the tag maven to your question.

maaartinus
  • 44,714
  • 32
  • 161
  • 320
1

I faced all the errors as above. Below is the fix

$ export CLASSPATH=/home/deepakkv/projects/poc/benchmarkparquet/target/classes:~/.m2/repository/com/google/caliper/caliper/0.5-rc1/caliper-0.5-rc1.jar:~/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar:/home/deepakkv/softwares/google-gson-2.2.3/gson-2.2.3.jar

$ java com.google.caliper.Runner com.parquet.benchmark.BenchmarkParquetDirectWrites 0% Scenario{vm=java, trial=0, benchmark=TestContains1, length=1} 6.42 ns; σ=0.46 ns @ 10 trials 50% Scenario{vm=java, trial=0, benchmark=TestContains2, length=1} 5.46 ns; σ=0.26 ns @ 10 trials

benchmark ns linear runtime TestContains1 6.42 ============================== TestContains2 5.46 =========================

vm: java trial: 0 length: 1

deepujain
  • 657
  • 1
  • 10
  • 17