Does it possible to include a jar in jar?

E

Earth

Hi all,

It is said that a jar could contains another jar.

I am trying it but fails. The testing step are as follows.

1. create a class AClass in com (1st package)
2. create another class AClass in dom (2nd package)
3. com.AClass with a reference to dom.AClass
4. create the com.jar
5. create the dom.jar
6. add dom.jar to com.jar
7. Run com.AClass gives class not found exception.

It appears that my test fails. Am I missing anything?

Please enlighten me.

Thanks in advance for any ideas or inputs.

Earth
 
A

Andrew Thompson

It is said that a jar could contains another jar.

Who says that? Got a link?
I am trying it but fails. The testing step are as follows.

1. create a class AClass in com (1st package)
2. create another class AClass in dom (2nd package)
3. com.AClass with a reference to dom.AClass
4. create the com.jar
5. create the dom.jar
6. add dom.jar to com.jar

I have not had much experience with this, but various
people suggest [ Who? URL?? ;-) ] unpacking the first
jar before adding it to the second.

To put that another way, you do not add the
include *jar* to the final jar file, but
merely it's classes.

See if that works for you.
 
B

Brian Palmer

Hi all,

It is said that a jar could contains another jar.

In the sense that a zipfile can contain another zipfile. Not, by
default, in the sense you're talking about.

You can make it work by creating your own ClassLoader that knows to
retrieve the jar-file and parse it (using the java.util.jar.* and
java.util.zip.* classes) to load a class file.
 
T

Tor Iver Wilhelmsen

It is said that a jar could contains another jar.

Sure it can - after all, it's just another file.

However, the normal ClassLoader will not look for that included jar,
so it's rather pointless, except in an archive for an installer for
instance.
It appears that my test fails. Am I missing anything?

Yes, you need a custom ClassLoader that looks for jars in the jar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top