javamavencaliper

google Caliper example test doesn't work?


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.


Solution

  • 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.