[英].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. 我使用的是导入到Eclipse的.jar文件,当我使用Eclipse运行该应用程序时,效果很好。
But when I try running it from the command line with just the command java ClassName
I get a NoClassDefFoundError
message. 但是,当我尝试仅使用命令
java ClassName
从命令行运行它时,会收到NoClassDefFoundError
消息。
The .jar file is in the same directory as the main class I need to run. .jar文件与我需要运行的主类位于同一目录中。
I tried using the classpath command in the terminal 我尝试在终端中使用classpath命令
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? 为什么我的程序不能在Eclipse中运行,而不能单独运行?
我猜您需要使用: java -classpath .:pack.jar ClassName
。
NoClassDefFoundError
will come if a class was present during compile time but not available in java classpath during runtime. 如果在编译期间存在某个类,但在运行时在Java类路径中不提供该类,则将出现
NoClassDefFoundError
。
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, 它甚至不接近等于
ClassNotFoundException
,因此nu请勿将它们混淆在一起,因此您需要包括.jar文件的whoe路径,
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. 请使用前面说明的技术来执行此操作,或者如果它是一个不经常使用而又不使用
java -classpath ..
调用的jar文件,请尝试将该文件导入OS类路径目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.