Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassPath in manifest does not work

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?

like image 916
Cosdix Avatar asked Dec 15 '22 10:12

Cosdix


2 Answers

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.

like image 146
Marko Topolnik Avatar answered Dec 29 '22 02:12

Marko Topolnik


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

like image 30
JB Nizet Avatar answered Dec 29 '22 03:12

JB Nizet