简体   繁体   English

.jar文件仅在Eclipse中使用时有效

[英].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.

相关问题 setIconImage仅在eclipse中起作用,当导出为可运行的jar文件时不起作用 - setIconImage only works in eclipse, doesnt work when exported as runnable jar file GSON:运行jar文件时出现MalformedJsonException(在Eclipse中工作正常) - GSON: MalformedJsonException when running the jar file (works fine in Eclipse) 将数据导出到Excel可以在Eclipse中工作,但打包成.jar文件时则不能工作 - Exporting data to Excel works in eclipse but not when packaged as a .jar file JAR中的游戏仅在Eclipse中有效 - Game in JAR works only inside Eclipse JDBC连接在IDE(eclipse)中工作,但不在.jar文件中工作 - JDBC connection works in IDE (eclipse), but not in .jar file 程序可以在eclipse中运行,但是不能导出到jar文件中 - program works in eclipse but not after exported into a jar file 在Eclipse上执行我的程序时批处理文件运行,但是使用jar文件时出现问题 - Batch file runs when executing my program on eclipse but the has issue when jar file is used 程序在Eclipse中与库一起工作,但在提取到jar中时不起作用 - Program works in eclipse with libraries but not when extracted to jar 将.txt文件读入JAR。 它在Eclipse中有效,但在导出的JAR中无效 - Reading a .txt file into JAR. It works in Eclipse but not in exported JAR 通过可执行jar运行时,JPA不起作用,但在Eclipse中起作用 - JPA not works when run via executable jar, but works in eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM