简体   繁体   English

运行jar时java.lang.ClassNotFoundException且其依赖项位于同一目录中

[英]java.lang.ClassNotFoundException when running a jar and its dependency is in the same directory

On eclipse I compiled a jar file. 在eclipse上,我编译了一个jar文件。 It uses several external archives on a mapped netwrok drive. 它在映射的netwrok驱动器上使用多个外部存档。 The project runs on eclipse perfectly. 该项目在Eclipse上完美运行。

I have copied the jar + all of the dependecy jars into some Solaris directory. 我已经将jar +所有的依赖jars复制到某个Solaris目录中。 Then I tried 然后我尝试

java -jar myapp.jar

and it gave me the following error: 它给了我以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: confmng/ConfigManager

This class specified in the error message is inside one of the mapped jars which I have copied to the same directory as the main jar. 错误消息中指定的此类位于已映射的jar之一内,我已将其复制到与主jar相同的目录中。

Also, I pinged the server where the dependency jars are located from the solaris and it was positive. 此外,我从solaris ping了依赖项jar所在的服务器,它是肯定的。

You can also see that ConfigManager class inside confmng package is really in the dependency jar: 您还可以看到confmng包中的ConfigManager类确实在依赖项jar中:

在此处输入图片说明

What could be wrong? 有什么事吗

Thanks 谢谢

You have to specify the classpath for the dependencies, you can specify at Manifest classpath, or at the java -jar myapp.jar command with -classpath parameter. 您必须为依赖项指定类路径,可以在清单类路径中或在带有-classpath参数的java -jar myapp.jar命令中指定。

Example: 例:

java -classpath dependency1.jar;subfolder/dependency2.jar;myapp.jar package.of.your.main.Class

You can also export a Runnable Jar in Eclipse, so there will be some options to handle with the dependencies, like the option "Package required libraries into generated JAR". 您还可以在Eclipse中导出Runnable Jar,因此会有一些选项可以处理依赖项,例如选项“将所需的库打包到生成的JAR中”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行java -jar时的java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when running java -jar 运行JAR时出现“ java.lang.ClassNotFoundException:javax.ejb.EJBObject” - “java.lang.ClassNotFoundException: javax.ejb.EJBObject” when running JAR 从jar文件加载类时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when loading a class from a jar file 带jar文件的Crontab java.lang.ClassNotFoundException - Crontab java.lang.ClassNotFoundException with a jar file 尽管添加了依赖项,但java.lang.ClassNotFoundException - java.lang.ClassNotFoundException inspite of adding dependency 运行appium脚本时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException is comming when running appium script 在Spark集群上运行程序时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when running program on spark cluster 在 IntelliJ IDEA 中运行时出现 java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when running in IntelliJ IDEA 尝试注入正在运行的 VM 时出现 java.lang.ClassNotFoundException 错误 - java.lang.ClassNotFoundException Error when trying to inject into running VM 从控制台运行java.lang.ClassNotFoundException - java.lang.ClassNotFoundException running from the console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM