Manual setting CLASSPATH with -cp or -classpath does not work as expected
classpath, jar, java
Solution
What about
java -cp /path/to/someJar.jar MyClassWithMainMethod
If you don't give Java the complete path to the jar file, how do you expect that it would find it?
OK well the argument you give to "-cp" is the same sort of thing you use with the CLASSPATH variable - what happens when you do this:
java -cp .:someJar.jar MyClassWithMainMethod
Problem
MyClassWithMainMethod.java uses classes of someJar.jar. If I call: ``` java -cp someJar.jar MyClassWithMainMethod ``` I get the exception: ``` Exception in thread "main" java.lang.NoClassDefFoundError: MyClassWithMainMethod Caused by: java.lang.ClassNotFoundException: MyClassWithMainMethod at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:315) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330) at java.lang.ClassLoader.loadClass(ClassLoader.java:250) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398) ``` But when I set the CLASSPATH to my jar manually ``` export CLASSPATH=:/path/to/someJar.jar ``` it works calling ``` java MyClassWithMainMethod ``` What am I doing wrong?