Class not found despite classpath in MANIFEST

I have this jar:

/mybundle.jar/
    de/mybundle/myclass.class
    lib/mysql.jar
    META-INF/MANIFEST.MF

      

With the next MANIFEST.MF

Manifest-Version: 1.0
Class-Path: lib/mysql.jar
Main-Class: de.mybundle.myclass

      

Everything seems perfectly correct to me, but when I run

java -jar mybundle.jar

      

I am getting a NoClassDefFoundException when a class tries to instantiate one of the MySQL library classes.

What have I done wrong?

+3


source to share


2 answers


You cannot link jar files in other jar files. The paths given in the manifest are relative to the location of the jar file you are calling, so in your case relative to location mybundle.jar

.

You have two options:



  • Or put MySQL in a lib directory outside yours mybundle.jar

    .
  • Create a bold jar that contains all the classes from the required jar files in addition to your own classes. This is available from Eclipse or Maven .
+1


source


If your mybundle.jar is in c: / foo, your mysql.jar is in c: / foo / lib. The class path in the manifest is relative to the executable JAR, as you wrote it.



0


source







All Articles