Probably dumb JAR question

T

Tom Anderson

Evening all,

I have a program which uses some external libraries, which i have as JARs.
I want to package my program up as an executable JAR. Can i put the
libraries inside the executable JAR somehow?

I believe the answer is no, but i thought i'd ask.

My options, then, are to package my code into a JAR, and then have the
library JARs travel alongside the app JAR, or to unpack the library JARs
and pack all the class files together into one big huge JAR, right?

Well, or write a custom classloader that will load classes from JARs
inside another JAR.

Thanks,
tom
 
A

Arne Vajhøj

Tom said:
I have a program which uses some external libraries, which i have as
JARs. I want to package my program up as an executable JAR. Can i put
the libraries inside the executable JAR somehow?

I believe the answer is no, but i thought i'd ask.

My options, then, are to package my code into a JAR, and then have the
library JARs travel alongside the app JAR, or to unpack the library JARs
and pack all the class files together into one big huge JAR, right?

Well, or write a custom classloader that will load classes from JARs
inside another JAR.

I think that summarizes the options rather well !

:)

Arne
 
Q

Qu0ll

Evening all,

I have a program which uses some external libraries, which i have as JARs.
I want to package my program up as an executable JAR. Can i put the
libraries inside the executable JAR somehow?

I believe the answer is no, but i thought i'd ask.

My options, then, are to package my code into a JAR, and then have the
library JARs travel alongside the app JAR, or to unpack the library JARs
and pack all the class files together into one big huge JAR, right?

Well, or write a custom classloader that will load classes from JARs
inside another JAR.

Tom,

Have you seen ProGuard? It's great. I use it to package everything in one
JAR and also to shrink, obfuscate and optimize. And it's free.

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
(e-mail address removed)
[Replace the "SixFour" with numbers to email me]
 
T

Tom Anderson


Aha! I'm going to have to play with that.

I went ahead and made a merged JAR, and it runs. However, i'm not too sure
about this as a general solution, because it could screw up processes
which depend on metadata in the manifest. I handcrafted a manifest which
contained the named sections from the manifests of the JARs i merged, but
i still had to throw away a lot of metadata that wasn't in named sections.
Using the funky One-JAR classloader might be a cleaner solution.

tom
 
T

Tom Anderson

Have you seen ProGuard? It's great. I use it to package everything in
one JAR and also to shrink, obfuscate and optimize. And it's free.

Thanks, i'll take a look at it.

tom
 
R

Roedy Green

I have a program which uses some external libraries, which i have as JARs.
I want to package my program up as an executable JAR. Can i put the
libraries inside the executable JAR somehow?

You can put any data you want inside the jar, and get at it with
getResource. However, if you want to put jar files in there, they
won't be much use until you fish them out. Java won't go looking in
nested jars for class files unless you write a custom class loader.

What you probably want to do in unpack your library jars and repack
them into to one big jar, or distribute the various jars separately.

There are tools in JNLP and in the manifest to link the jars together.

see http://mindprod.com/jgloss/jnlp.html
http://mindprod.com/jgloss/manifest.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Here is a point of no return after which warming becomes unstoppable
and we are probably going to sail right through it.
It is the point at which anthropogenic (human-caused) warming triggers
huge releases of carbon dioxide from warming oceans, or similar releases
of both carbon dioxide and methane from melting permafrost, or both.
Most climate scientists think that point lies not far beyond 2°C (4°F) C hotter."
~ Gwynne Dyer
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top