making sure a jar is self-contained

Discussion in 'Java' started by Roedy Green, Jun 16, 2005.

  1. Roedy Green

    Roedy Green Guest

    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
    Roedy Green, Jun 16, 2005
    #1
    1. Advertising

  2. Roedy Green

    Bjorn Borud Guest

    [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.

    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
    Bjorn Borud, Jun 17, 2005
    #2
    1. Advertising

  3. Roedy Green

    Bjorn Borud Guest

    ["John Currier" <>]
    | 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
    Bjorn Borud, Jun 17, 2005
    #3
  4. Roedy Green

    John Currier Guest

    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
    John Currier, Jun 17, 2005
    #4
  5. Roedy Green

    Mark Rose Guest

    > 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.
    Mark Rose, Jun 17, 2005
    #5
  6. Roedy Green

    John Currier Guest

    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
    John Currier, Jun 17, 2005
    #6
  7. Roedy Green

    Roedy Green Guest

    On Thu, 16 Jun 2005 21:50:22 GMT, Roedy Green
    <> wrote or quoted :

    >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
    Roedy Green, Jun 17, 2005
    #7
  8. Roedy Green

    Bjorn Borud Guest

    ["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.

    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
    Bjorn Borud, Jun 17, 2005
    #8
  9. Roedy Green

    Rogan Dawes Guest

    Roedy Green wrote:
    > On Thu, 16 Jun 2005 21:50:22 GMT, Roedy Green
    > <> wrote or quoted :
    >
    >
    >>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.
    >
    >


    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
    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, Jun 23, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    572
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    591
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    396
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    371
    falcon
    Jul 31, 2005
  5. Bart Kastermans
    Replies:
    6
    Views:
    396
    Bart Kastermans
    Jul 13, 2008
Loading...

Share This Page