I have an external library(just one class file called org.vinay.dep.DependedClass).It is well within
its package directory structure and directory org is on Desktop.
And I have a jar called a.jar which has dependency on my external lib.
Executing jar -tf a.jar gives below output,
META-INF/
META-INF/MANIFEST.MF
com/
com/os/
com/os/hw/
com/os/hw/HelloWorld.class
com/os/hw/HwUtil.class
I tried to run the jar in 2 ways
-
java -classpath C:/Users/vinay/Desktop -jar a.jarwith
manifest.mf entries beingManifest-Version: 1.0
Created-By: 1.6.0_05 (Sun
Microsystems Inc.)
Main-Class: com.os.hw.HelloWorldand got NoClassDefFoundError for DependedClass
-
java -jar a.jarafter changing manifest entries as belowManifest-Version: 1.0
Created-By: 1.6.0_05 (Sun
Microsystems Inc.)
Main-Class: com.os.hw.HelloWorld
Class-Path: C:/Users/vinay/DesktopBut this time it throwed NoClassDefFoundError for HelloWorld
class itself
When i package my external lib into jar and use the jar name for Class-Path entry in manifest file it works.Is there a way to resolve this problem without packaging external lib into jar?
I don’t think you can combine -classpath and -jar. You can instead do it like this:
This assumes a.jar is in the current folder (or you can add full path to a.jar as well).
Hardcoding the Class-Path entry of your manifest to a path on your local machine is never the correct solution 🙂