How to include a JAR file within a JAR file?

Discussion in 'Java' started by laredotornado, Jan 19, 2011.

  1. Hi,

    I'm using Java 6. Is it possible to include a JAR file within a JAR
    file? Thanks, - Dave
     
    laredotornado, Jan 19, 2011
    #1
    1. Advertising

  2. On 01/19/2011 02:18 PM, laredotornado wrote:
    > Hi,
    >
    > I'm using Java 6. Is it possible to include a JAR file within a JAR
    > file? Thanks, - Dave


    Not practically. Why would you want to?

    --

    Knute Johnson
    s/nospam/knute2011/
     
    Knute Johnson, Jan 19, 2011
    #2
    1. Advertising

  3. laredotornado

    Arne Vajhøj Guest

    On 19-01-2011 17:18, laredotornado wrote:
    > 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
     
    Arne Vajhøj, Jan 20, 2011
    #3
  4. laredotornado

    markspace Guest

    On 1/19/2011 2:18 PM, laredotornado wrote:

    > 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.
     
    markspace, Jan 20, 2011
    #4
  5. laredotornado

    Lew Guest

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


    Arne Vajhøj wrote:
    > 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.

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 20, 2011
    #5
  6. On 19-01-2011 19:28, Lew wrote:
    > laredotornado wrote:
    >>> I'm using Java 6. Is it possible to include a JAR file within a JAR
    >>> file?

    >
    > Arne Vajhøj wrote:
    >> 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".


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

    Arne
     
    Arne Vajhøj, Jan 20, 2011
    #6
  7. On 01/19/2011 05:18 PM, laredotornado wrote:
    > 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....


    --
    Beware of bugs in the above code; I have only proved it correct, not
    tried it. -- Donald E. Knuth
     
    Joshua Cranmer, Jan 20, 2011
    #7
  8. On 01/19/2011 04:41 PM, Arne Vajhøj wrote:
    > On 19-01-2011 19:28, Lew wrote:
    >> laredotornado wrote:
    >>>> I'm using Java 6. Is it possible to include a JAR file within a JAR
    >>>> file?

    >>
    >> Arne Vajhøj wrote:
    >>> 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".

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


    I did too.

    --

    Knute Johnson
    s/nospam/knute2011/
     
    Knute Johnson, Jan 20, 2011
    #8
  9. laredotornado

    Lew Guest

    Lew wrote:
    >>> 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".


    Arne Vajhøj wrote:
    >> I assumed that he wanted to execute the code inside the jars
    >> inside the jar.


    Knute Johnson wrote:
    > 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).

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 20, 2011
    #9
  10. On 20.1.2011 3:26, Joshua Cranmer wrote:
    > On 01/19/2011 05:18 PM, laredotornado wrote:
    >> 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....
    >


    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.

    --

    Lord, what fools these mortals be!
    -- William Shakespeare, "A Midsummer-Night's Dream"
     
    Donkey Hottie, Jan 20, 2011
    #10
  11. laredotornado

    Lew Guest

    Donkey Hottie wrote:
    > However, some JEE containers extract all the contents of EAR or WAR
    > before use.


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

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 20, 2011
    #11
  12. On 20-01-2011 04:15, Lew wrote:
    > Donkey Hottie wrote:
    >> However, some JEE containers extract all the contents of EAR or WAR
    >> before use.

    >
    > 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
     
    Arne Vajhøj, Jan 21, 2011
    #12
  13. laredotornado

    Lew Guest

    On 01/20/2011 08:10 PM, Arne Vajhøj wrote:
    > On 20-01-2011 04:15, Lew wrote:
    >> Donkey Hottie wrote:
    >>> However, some JEE containers extract all the contents of EAR or WAR
    >>> before use.

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


    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.

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 21, 2011
    #13
  14. On 20-01-2011 20:55, Lew wrote:
    > On 01/20/2011 08:10 PM, Arne Vajhøj wrote:
    >> On 20-01-2011 04:15, Lew wrote:
    >>> Donkey Hottie wrote:
    >>>> However, some JEE containers extract all the contents of EAR or WAR
    >>>> before use.
    >>>
    >>> 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.

    >
    > 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
     
    Arne Vajhøj, Jan 21, 2011
    #14
  15. "Lew" <> wrote in message
    news:ih8ucb$lup$...
    > Donkey Hottie wrote:
    >> However, some JEE containers extract all the contents of EAR or WAR
    >> before use.

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


    Unpacking wars is optional behavior in Tomcat.
     
    Mike Schilling, Jan 21, 2011
    #15
  16. laredotornado

    Roedy Green Guest

    On Wed, 19 Jan 2011 14:18:22 -0800 (PST), laredotornado
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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.
     
    Roedy Green, Jan 21, 2011
    #16
  17. On 20.1.2011 11:15, Lew wrote:
    > Donkey Hottie wrote:
    >> However, some JEE containers extract all the contents of EAR or WAR
    >> before use.

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

    --

    Chess tonight.
     
    Donkey Hottie, Jan 21, 2011
    #17
  18. laredotornado

    Lew Guest

    Donkey Hottie wrote:
    > 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?

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 22, 2011
    #18
  19. On 22.1.2011 2:05, Lew wrote:
    > Donkey Hottie wrote:
    >> 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?
    >


    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;))

    --

    A kind of Batman of contemporary letters.
    -- Philip Larkin on Anthony Burgess
     
    Donkey Hottie, Jan 22, 2011
    #19
  20. laredotornado

    Lew Guest

    On 01/21/2011 08:22 PM, Donkey Hottie wrote:
    > On 22.1.2011 2:05, Lew wrote:
    >> Donkey Hottie wrote:
    >>> 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?
    >>

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

    --
    Lew
    Ceci n'est pas une pipe.
     
    Lew, Jan 22, 2011
    #20
    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. Earth
    Replies:
    4
    Views:
    15,604
    Québec
    Aug 8, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    588
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,732
    muttley
    Oct 20, 2005
  4. mark4asp
    Replies:
    2
    Views:
    2,220
    Harry Haller
    Nov 7, 2006
  5. Andreas Bogenberger
    Replies:
    3
    Views:
    935
    Andreas Bogenberger
    Feb 22, 2008
Loading...

Share This Page