ClassPath in manifest does not work

倾然丶 夕夏残阳落幕 提交于 2019-12-23 20:14:03

问题


Structure of files in my jar is:

com/my/Main.class
META-INF/MANIFEST.MF
RXTXcomm.jar

Manifest.mf consist:

Manifest-Version: 1.0
Main-Class: com.my.Main
Class-Path: RXTXcomm.jar

(empty line present)

When I run my jar as: java -jar my.jar

I get: Exception in thread "main" java.lang.NoClassDefFoundError: gnu/io/SerialPortEventListener

What is wrong?


回答1:


What is wrong?

You have packaged the jar dependency inside your main jar. The intention of Class-Path is to add an external jar to the classpath, with the path relative to the location of the main jar.

Packaging a jar within a jar is not supported by standard Java classloaders. If you want, you can explode the inner jar into the main jar, though. Maven can do this for you.




回答2:


The RXTXcomm.jar must not be inside the jar file, but outside of it. Read the tutorial.



来源:https://stackoverflow.com/questions/16610333/classpath-in-manifest-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!