How to include a JAR file within a JAR file?

L

laredotornado

Hi,

I'm using Java 6. Is it possible to include a JAR file within a JAR
file? Thanks, - Dave
 
A

Arne Vajhøj

I'm using Java 6. Is it possible to include a JAR file within a JAR
file?

Not out of the box.

You can special classloaders that can do such magic, but the
practical solution is to place all the jar files in the file
system.

And actually it do have some advantages because it allow
to update one or more independently of the rest.

Arne
 
M

markspace

I'm using Java 6. Is it possible to include a JAR file within a JAR
file?


http://one-jar.sourceforge.net/

But this should be a last resort. Check out Java Web Start. Also, you
can deliver several Jar files in a zip file and then unpack them, and
have a class path set to the required Jars. Both of these options
should be explored before resorting to the OneJAR code above.
 
L

Lew

Not out of the box.

You can special classloaders that can do such magic, but the
practical solution is to place all the jar files in the file
system.

And actually it do have some advantages because it allow
to update one or more independently of the rest.

Actually, you can put a JAR file inside a JAR file, just like you can put a
ZIP file inside a ZIP file. It won't do you much good, but you can do it.

Everyone assumes the OP wants to use the inner JAR file as a classpath
element, but he didn't actually say that. All he asked was if it's possible
to include a JAR file inside another, and of course that's a big resounding "Yes".

As Knute Johnson asked,
Why would you want to?

It is likely that the OP will be disappointed with the usefulness of doing
what he asked.
 
A

Arne Vajhøj

Actually, you can put a JAR file inside a JAR file, just like you can
put a ZIP file inside a ZIP file. It won't do you much good, but you can
do it.

Everyone assumes the OP wants to use the inner JAR file as a classpath
element, but he didn't actually say that. All he asked was if it's
possible to include a JAR file inside another, and of course that's a
big resounding "Yes".

I assumed that he wanted to execute the code inside the jars
inside the jar.

Arne
 
J

Joshua Cranmer

I'm using Java 6. Is it possible to include a JAR file within a JAR
file? Thanks, - Dave

Well, a JAR file is a file, so you can put it in a JAR file. On the
other hand, using a JAR file within another one is a bit of a different
matter....
 
L

Lew

Knute said:
I did too.

That makes you part of "everyone". But Knute, you asked him anyway why he
would want to, so at least you tested your assumption (assuming he answers
your question).
 
D

Donkey Hottie

Well, a JAR file is a file, so you can put it in a JAR file. On the
other hand, using a JAR file within another one is a bit of a different
matter....

Indeed. A WAR file is a JAR file, and usually contains JAR files which
can be used. An EAR file is JAR file, and usually contains WAR files and
JAR files... And they are all used!

However, some JEE containers extract all the contents of EAR or WAR
before use.
 
A

Arne Vajhøj

I don't know of any that don't.

Me neither.

But it would be doable. All that is needed is that the
server comes with a classloader capable of doing it. And
that JSP pages were compiled in memory not to disk.

But the app server vendors can probably not see any reason
to do so.

Arne
 
L

Lew

Me neither.

But it would be doable. All that is needed is that the
server comes with a classloader capable of doing it. And
that JSP pages were compiled in memory not to disk.

But the app server vendors can probably not see any reason
to do so.

A big reason not to do so is that it would defeat the role of "deployer" in
their ability to tweak deployment descriptors and property files.
 
A

Arne Vajhøj

A big reason not to do so is that it would defeat the role of "deployer"
in their ability to tweak deployment descriptors and property files.

Why?

Those should be tweaked before deployment.

Tweaking the files after the app server has expanded
the ear/war is not good.

Arne
 
R

Roedy Green

I'm using Java 6. Is it possible to include a JAR file within a JAR
file? Thanks, - Dave

you could using WinZip but it would not be useful. Unpack the jar and
add its element if you want java to be able to use the contents.
--
Roedy Green Canadian Mind Products
http://mindprod.com
To err is human, but to really foul things up requires a computer.
~ Farmer's Almanac
It is breathtaking how a misplaced comma in a computer program can
shred megabytes of data in seconds.
 
D

Donkey Hottie

I don't know of any that don't.

I remember having been with WebLogic, and we had to manually extract our
WAR in that. It supports extracted and unextracted WAR files, but you
have to manually extract if that is a requirement for the application.

That was WebLogic 8.1.
 
L

Lew

Donkey said:
I remember having been with WebLogic, and we had to manually extract our
WAR in that. It supports extracted and unextracted WAR files, but you
have to manually extract if that is a requirement for the application.

That was WebLogic 8.1.

I use WebLogic 10.x and later and they don't do that. You can just deploy an
"unextracted" WAR. It creates a working (extracted) copy in its temporary
directories.

Are you absolutely certain 8.1 didn't do that?
 
D

Donkey Hottie

I use WebLogic 10.x and later and they don't do that. You can just
deploy an "unextracted" WAR. It creates a working (extracted) copy in
its temporary directories.

Are you absolutely certain 8.1 didn't do that?

Nope. It's just how I remember. We tried to access "some files in the
war" but could not in WebLogic, in Tomcat t worked. But when we deployed
as an extracted folder, it worked.

Dunno. I was a newbie with J2EE back then (that it is pretty much
different now, I'm a guru;))
 
L

Lew

Nope. It's just how I remember. We tried to access "some files in the
war" but could not in WebLogic, in Tomcat t worked. But when we deployed
as an extracted folder, it worked.

Dunno. I was a newbie with J2EE back then (that it is pretty much
different now, I'm a guru;))

I'm a little puzzled myself, and not near the particular WebLogic environment
just now anyway. I think it might have to do with the fact that the unpacked
stuff is in a temporary directory and not really somewhere comfortable.

Doesn't the Java EE spec require containers to accept either a WAR or
directory-based deployment? Maybe not and I'm too lazy right now to look it
up. I don't think there's anything in there that requires a container to
unpack a WAR, but I figure it's the easiest way to deploy a WAR, just as
unpacking a ZIP-based application is the easiest way to deploy it.
 

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,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top