简体   繁体   中英

Java command line launcher

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=/something tells the JVM where to find native libraries -- ie, DLLs. It has nothing to do with finding jar files, so if you're using that flag to locate jar files, 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.Test really does contain the class in question, and inside the jar file the Test.class file is in a test directory in a net directory.

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 -cp argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM