I get a NoClassDefFoundError when trying to run a Java class without providing the proper class path. However when added the needed class path, java complaints it cannot find the main method. If you have any idea of what's happening here, please point me in the right direction. Thank you
$ java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: cern/colt/matrix/DoubleMatrix1D
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
... 6 more
$ java -cp resources/colt.jar MyClass
Error: Could not find or load main class MyClass
Assuming MyClass isn't in a package, you need something like (on Windows)
java -cp resources/colt.jar;. MyClass
or (otherwise)
java -cp resources/colt.jar:. MyClass
To also include the current directory. Alternatively, you can set the CLASSPATH environment variable.
On Windows,
set "CLASSPATH=resources/colt.jar;."
otherwise something like (depending on your shell)
export CLASSPATH="resources/colt.jar:."
then
java MyClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With