So I’m trying to launch a jar from the command line using these arguments similar to these:
java -cp "path/test.jar;path/lib.jar" -Djava.library.path="path/another_lib.jar" net.test.Test
(net.test.Test is the main class) Which gives me a NoClassDefFoundError Exception (for net/test/Test).
This seems to work fine for other people, so I’m not sure why it isn’t working.
First,
-Djava.library.path=/somethingtells the JVM where to find native libraries — i.e., DLLs. It has nothing to do with findingjarfiles, so if you’re using that flag to locatejarfiles, that’s going to be a problem right there.Otherwise, this is fine. You need to make sure all of those paths are correct, and the jar file containing
net.test.Testreally does contain the class in question, and inside the jar file theTest.classfile is in atestdirectory in anetdirectory.As Rup points out in a comment, if there are any classes in your current directory that you need to pick up, you’ll want to add an entry for “.”, the current directory, to the
-cpargument.