I’m trying to use a third-party package (call it ‘foo.bar’). It’s in a jar file in the current directory (foo.bar.jar). I’m trying to run the following super basic “hello-world”-style program:
package foo.bar.bla;
import foo.bar.*;
import foo.bar.somethingelse.SomeException;
public class HelloWorld implements SomethingInFooBar {
public static void main(String[] args) throws SomeException {
System.out.println("Hello World!");
}
}
It compiles just fine when I use javac -cp foo.bar.jar HelloWorld.java.
But when I try to run it (using java HelloWorld), I always get NoClassDefFoundError (wrong name) error, along with a /-separated package path (some/path/like/this/HelloWorld) of where the class ostensibly lies. But when I try to run it with the full path (as mentioned in other questions and on other sites addressing this problem), it still doesn’t work (using the command java path.it.gave.me.HelloWorld).
Thanks for any insight into this n00b problem. I should stop relying so much on Eclipse!
Generally this happens because your classpath is not being set up properly. Try adding the classpath to the
javacall as well as thejavaccall, e.g.,java -cp foo.bar.jar path.to.HelloWorld.