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