开发者

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

开发者 https://www.devze.com 2023-01-22 00:25 出处:网络
I have a jar file called \"a.jar\" which has another jar开发者_开发技巧 file called \"b.jar\".

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号