1

I need save my application, that included external JAR libraries, in single JAR file for future use as single lib. When I export it to JAR file, all nested jars append to archive, but not work as part of single lib. What I do wrong?

How can I make nested libraries private for external application?

Aleksey Leonov
  • 411
  • 1
  • 4
  • 10
  • Do you want to package third party jars in your executable jar ? – Sanjeev Apr 20 '16 at 10:04
  • 1
    Related: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven?rq=1 NB: There's no jar in jar possibility, that might be your issue –  Apr 20 '16 at 10:28
  • Make sure that within the `MANIFEST.MF` you have defined classpath (`Class-path: jarA jarB jarC`) referencing all the jars in lib – uniknow Apr 20 '16 at 10:28
  • @Sanjeev Yes, I want add to my lib third party jars from sdk. And make one "wrapper" lib – Aleksey Leonov Apr 20 '16 at 11:13
  • What others already said. I guess (but I have no additional informations) that you could write your own class loader which would expand jars from the classpath and then load classes from there (hard to do and probably not worth the effort); if you can, use a dependency manager like Maven. – watery Apr 20 '16 at 11:59

2 Answers2

0

I think jars in a jar is not supported. But you can always extract the external JAR libraries and than create a jar containing their content and your classes in one jar.

This way you can also remove the parts of the external libraries, you don't need, to reduce the size of the jar you create.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
0

Single Executable jar with all dependency nested is not possible by standard jar making process. Alternatively you can place all dependent jars in a folder parallel to your own executable jar.

There is another way to create Single Jar with all nested dependent jar with the help of One-Jar. I personally never tried this.

Hope this helps.

Sanjeev
  • 9,876
  • 2
  • 22
  • 33