making sure a jar is self-contained

R

Roedy Green

It there a utility that will trace dependencies to provide a list of
all the classes that need to be included to create a free-standing
jar?

It is embarrassing to give folks a jar missing classes. The app works
fine on your machine where the classes are available on the classpath.

Obviously it can't find dynamically loaded stuff, but usually you know
about that, and can use Jet to find those.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
B

Bjorn Borud

[Roedy Green <[email protected]>]
|
| It is embarrassing to give folks a jar missing classes. The app
| works fine on your machine where the classes are available on the
| classpath.

don't set the classpath -- don't assume anything about the
environment. include everything in the application jar. write a
manifest that identifies the main class. if it becomes 20Mb big it is
still smaller than the average web browser and you don't usually hear
anyone complaining about their disk footprint. (often it won't even
be that big.)

this means that if Java is installed all the user has to do to run the
application is

java -jar app.jar

(modulo any options you'd need to pass along to the JVM anyway)

no fiddling around.

-Bjørn
 
B

Bjorn Borud

["John Currier" <[email protected]>]
| How about setting your classpath to nothing and try to run the code.

the classpath environment variable should always be set to nothing.

-Bjørn
 
J

John Currier

How about setting your classpath to nothing and try to run the code.

But you said this "a free-standing jar". Do you mean one that you run
with java -jar? If so then your classpath settings shouldn't come into
the picture at all...and you wouldn't be asking this question.
Assuming, of course, that you haven't inappropriately put any
jars/classes into your JRE.

John
 
M

Mark Rose

It there a utility that will trace dependencies to provide a list of
all the classes that need to be included to create a free-standing
jar?

You can use GenJar (http://genjar.sourceforge.net). It packages only the
dependencies from starting point(s) you specify, like your main method.
You can specify exceptions which have to be included etc.

It hasn't been updated for a long time now and has some outstanding
issues which should only affect exotic needs. It does its job very well
otherwise.

Mark.
 
J

John Currier

I agree, but doesn't his question imply otherwise?

I definitely don't agree with you on bundling everything in one massive
jar. I guess you've never written anything that runs against a generic
database. My SchemaSpy (a runnable jar) would be MANY megabytes (vs.
88KB) if I tried to include every database driver I could think of into
my jar. I'm not sure how you would expect someone to handle the
various versions of drivers that exist for any given database vendor.

John
http://schemaspy.sourceforge.net
 
R

Roedy Green

It is embarrassing to give folks a jar missing classes. The app works
fine on your machine where the classes are available on the classpath.

there are two issues. One is testing. That can be done by temporarily
setting the classpath to empty.

The other is figuring out what to put in the jar, rather than finding
out one class at a time per test, or per JET compile.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
B

Bjorn Borud

["John Currier" <[email protected]>]
| I agree, but doesn't his question imply otherwise?
|
| I definitely don't agree with you on bundling everything in one massive
| jar. I guess you've never written anything that runs against a generic
| database. My SchemaSpy (a runnable jar) would be MANY megabytes (vs.
| 88KB) if I tried to include every database driver I could think of into
| my jar. I'm not sure how you would expect someone to handle the
| various versions of drivers that exist for any given database vendor.

I am talking about self-contained applications where the dependencies
are known up front. in this scenario a few megabytes of bytecode
matters significantly less than people needing to ask "what jar
provides..." N times before they get it to run.

-Bjørn
 
R

Rogan Dawes

Roedy said:
there are two issues. One is testing. That can be done by temporarily
setting the classpath to empty.

The other is figuring out what to put in the jar, rather than finding
out one class at a time per test, or per JET compile.

Try proguard: http://proguard.sourceforge.net

It has other features as well (optimising, obfuscating), but it can be
used as a pure "dependency follower".

I use it to generate a complete self-contained jar for WebScarab, by
sucking in only the classes required from the various jars I depend on.

Regards,

Rogan
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top