Reputation:
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?
Upvotes: 3
Views: 19134
Reputation: 115388
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.
Upvotes: 1
Reputation: 849
There is another thread here that explains how to package jars for releases, including using Ant, jarjar and eclipse plugins.
Upvotes: 1
Reputation: 8024
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>
Upvotes: 6
Reputation: 1503290
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:
My vote is to keep the jar files separate.
Upvotes: 7
Reputation: 13686
This question seems probable duplicate. Please try to find answer from similar article in this forum Clean way to combine multiple jars
Upvotes: 2
Reputation: 75659
Jar files are just ZIP files, so you can try to unzip all jars, put all files together and then ZIP them again.
Upvotes: 0