开发者

Can i combine many jar files in one jar file

I 开发者_运维百科have multiple JAR files, which I have to add to classpath in Eclipse.

Is it possible to combine 30 files in one file and include that file?


You can, but I don't think it would necessarily be a good idea to do so. Three possible reasons, and no doubt there are more:

  • It makes it harder to see where any one constituent file comes from.
  • It makes it harder to replace just one library
  • If there are files which are contained in multiple jar files, which should "win"? For example, all the jar files will have their own manifest... you may be able to merge them all, but not necessarily... and for other files there may well simply not be a sensible way of merging them.

My vote is to keep the jar files separate.


Your may want to have a look at jarjar.

If you use an ant task you can also go for zipgroupfileset:

<zip destfile="jarlibrary.jar">
    <zipgroupfileset dir="lib" includes="*.jar"/>
</zip>


There are a number of existing tools for this:

  • Uberjar
  • Megajar
  • Onejar


This question seems probable duplicate. Please try to find answer from similar article in this forum Clean way to combine multiple jars


The jarjar project is what you need.


There is another thread here that explains how to package jars for releases, including using Ant, jarjar and eclipse plugins.


First, you can. JAR is just a ZIP file. You can extract all stuff into one directory, then create zip file (even manually using WinZip or similar tool), call the result *.jar (if you wish) and add it into the classpath.

The only problem that will probably happen is if several jar files contain resources with the same name (and path). for example, manfest.mf, or other descriptors. In most cases it will not cause any problem but sometimes if application code uses these resources you can have trouble.

There are some automatic tools that do this. Take a look on JarJar.

BUT the more important question: why do you want to do this? If you do not use maven put all library jars to one directory named lib under your project. Then add all these jars to your classpath in eclipse using 2-3 clicks. That's it.

if you are using maven, include all your direct dependences into your pom.xml, compile the project, then say mvn eclipse:eclipse. This will create .classspath and .project for you. Now just use it.


Jar files are just ZIP files, so you can try to unzip all jars, put all files together and then ZIP them again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜