ClassPath in manifest does not work
Asked Answered
E

2

5

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?

Epiglottis answered 17/5, 2013 at 13:29 Comment(0)
H
11

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.

Hydrostatic answered 17/5, 2013 at 13:36 Comment(2)
Then how to give relative path of the dependent jar that need to be packaged with the new jar?Heed
Simple answer is you cannot. Workaround may be to package them as Zip with the dependant jar in a subfolder. Then you can add Class-Path: subfolder/RXTXcomm.jar in the manifest of main jar.Ulberto
S
2

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

Stringhalt answered 17/5, 2013 at 13:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.