Reputation: 30018
I would like to use an external library (e.g. Google's Guava) for my Java program. I use Eclipse, so I downloaded Guava's jar (and source) and followed Adding a Java library to the project classpath to add it to Eclipse and to the buildpath of my project.
This works fine: I can run the program from Eclipse and from the runnable jar I export from Eclipse, but I get an error when I try to run directly from the bin/
dir, as I used to do before:
Exception in thread "main"
java.lang.NoClassDefFoundError: com/google/common/base/Joiner
What should I do?
Upvotes: 0
Views: 3633
Reputation: 17761
Youll have to tell Java where to find the library:
java -cp <path-to-lib-jar>;myJar.jar my.package.MyMainClass
or if you wanna use a jar file you can set the library path in the MANIFEST check here for an explanation.
Upvotes: 1
Reputation: 24788
To run the program on console as precise as possible with when you run it from Eclipse, you need to run it from the root directory of the project (not from bin) and don't forget to mention the classpath (http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/tooldocs/windows/classpath.html)
So for example on root you will run:
java -classpath lib/guava.jar;bin packageName.className
Upvotes: 0
Reputation: 2425
If you're running the class file directly from the project bin directory then you may have to specify the classpath manually:
C:> java -classpath C:\java\MyClasses;C:\java\OtherClasses MyClassHere
Upvotes: 1