File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes jars inside jar ? can it work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "jars inside jar ? can it work ?" Watch "jars inside jar ? can it work ?" New topic

jars inside jar ? can it work ?

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
i have jar that contains jars (this is used to be web application that contains the jars in the WEB-INF/lib dir , but now i need to export this
application as stand alone jar im export the application as jar file that contain the jars inside the jar when i run one of the application method
from out side class it dont find the jars even if its inside the jar
only when i put them in the classpath the method invoke like it should .
so to be sure jars cant be inside main application jar?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15092

Java doesn't support JARs inside JARs by itself.

You can have JAR files inside a WAR (in the WEB-INF/lib directory). The web container has a special classloader that will look for the JARs in the WEB-INF/lib directory inside a WAR.

But the normal Java launcher (used to run stand-alone Java apps) does not have any mechanism to look for classes in a JAR inside another JAR.

If you really want this you can write your own ClassLoader that supports this, but that's not so easy to do.
[ March 06, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jesper Young:

If you really want this you can write your own ClassLoader that supports this, but that's not so easy to do.

Or simply use

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Consider Paul's rocket mass heater.
subject: jars inside jar ? can it work ?
It's not a secret anymore!