1

Possible Duplicate:
Is it possible to create an “uber” jar containing the project classes and the project dependencies as jars with a custom manifest file?

I am looking at multiplatform deployments. One of the key things that is always frustrating in languages like Perl and Python is deploying third-party libraries and second-party libraries.

I was wondering if the java build process allows for packaging all non-JRE libraries used by a program into the jar such that it could be deployed anywhere without installing into any other directories.

Community
  • 1
  • 1
Paul Nathan
  • 39,638
  • 28
  • 112
  • 212

2 Answers2

1

No, jar files are not supposed to contain other jar files. It's possible to do so, but only with custom class loaders that make everything more complex. Why don't you just zip the jar and all its dependencies together:

myApp.zip
  |_bin
  |  |_ start.bat
  |  |_ start.sh
  |
  |_lib
     |_myApp.jar
     |_other.jar
     |_other2.jar
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Why can't I have jars in jars in jars? what if complex class-loaders and recursive compression is what REALLY turns me on.... sometimes you might like using jars in jars if your only other option is .zip because the compression is close to .7z. Assuming you can't connect to the internet that is and if that is the case then... Congratulations on reading this! – Mitch Connor Oct 17 '12 at 19:49
  • @TylerHeiks: I don't understand your question. jar files and zip files are the same thing. The same compression algorithm is used. – JB Nizet Oct 17 '12 at 19:52
  • > Why don't you just zip the jar and all its dependencies together - I don't know. :) I'm boning up on this stuff. I know that in Py/Perl, that would involve some bad hackery in the files to tell them to look at where they live on the filesystem for their libraries. I am hoping that Java can do better. – Paul Nathan Oct 17 '12 at 20:07
  • 1
    @TylerHeiks Shading / using `jarjar` is generally a less insane way of doing this. – millimoose Oct 18 '12 at 00:00
  • @JBNizet i didn't have a question and no- the algorithm is optimized from ur standard windows zip – Mitch Connor Oct 31 '12 at 17:03
1

I think you are looking for something like fatjar or uberjar.

That is step in the buildprocess, that uncompresses all dependencies and package them together in one large jar.

Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79