简体   繁体   中英

.jar file only works when used in Eclipse

I'm using a .jar file which I imported to Eclipse, and when I used Eclipse to run the application is works just fine.

But when I try running it from the command line with just the command java ClassName I get a NoClassDefFoundError message.

The .jar file is in the same directory as the main class I need to run.

I tried using the classpath command in the terminal

java -classpath pack.jar ClassName

but I got the same error but this time it was in the main thread

Exception in thread "main" java.lang.NoClassDefFoundError

Why does my program work in Eclipse but not on its own?

我猜您需要使用: java -classpath .:pack.jar ClassName

NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime.

Its Not Even Close To Being equal to ClassNotFoundException nu mustn't confuse them together, so u need to include the whoe path of the .jar file,

use the previously explained technique to do so, or if it was a jar file that want use frequently without using the call to java -classpath .. thing try importing the file into the OS class path directory.

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