aspose file tools
The moose likes Java in General and the fly likes Can a non-executable (ie class library) JAR file contain other JAR files? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Can a non-executable (ie class library) JAR file contain other JAR files?" Watch "Can a non-executable (ie class library) JAR file contain other JAR files?" New topic
Author

Can a non-executable (ie class library) JAR file contain other JAR files?

Faraz Syed
Greenhorn

Joined: Feb 12, 2009
Posts: 10
Is it possible for a non-executable (i.e. class library) JAR file to contain other JAR files (its dependencies perhaps) inside it? Perhaps bundled up inside a lib/ sub-directory?

Here is what I am trying to do:

I have an existing class library, mylib.jar.
I want to modify one class (e.g. MyClient) from mylib.jar by overriding a couple of its methods, and provide this modified version (MyNewClient) in the new JAR mynewlib.jar.
But I want the end result to be a single jar file that can be used as is without needing to include mylib.jar on the CLASSPATH.

So I just want my users to be able to say:

javac -cp mynewlib.jar MySource.java

instead of needing to reference the original mylib.jar as well on the CLASSPATH.

Is this possible?

I've spent some time with both Eclipse and Netbeans and this doesn't appear to be possible for non-executable Jar projects.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

A JAR file can contain anything you want, but the same limitation is there: the system class loader can't load classes that are in a JAR inside a JAR.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can a non-executable (ie class library) JAR file contain other JAR files?
 
Similar Threads
NetBeans IDE : Executable Jar
Imbedded jar file
jar files
Running jar from anywhere
packages/jars/libraries