简体   繁体   中英

how to run a class in the jar file which is in the classpath of another jar file

I have a jar file called "a.jar" which has another jar file called "b.jar".

a.jar
 |
 |-- META-INF
 |     |
 |     |-- MANIFEST.MF
 |
 |-- b.jar
     |
     |- com/test/MainInB.class

"b.jar" has com/test/MainInB.class file. (MainInB class just print out "hello world!")

"a.jar" has the MANIFES.MF like this:

Manifest-version: 1.0
Main-Class: com.test.MainInB
Class-Path: b.jar

(The manifest file does end with empty new line)


And I would like to run the a.jar like this so it prints out "hello world!"

java -jar a.jar

But I got NoClassDefFoundError!

Please Help! Is this not allowed? Or am I missing something?

R Joe

Java have a issue it can not read jars from inside of jar file.

They considered it for the future release. But not fixed till now see BUG .

You have to keep them again in lib

Actually my example works!

I'm just having problem with my project in which I use maven-assembly-plugin to create jar and MANIFEST.MF.

Something must be off in the configuration or the plugin.

Thanks anyway guys!

Joe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM