Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

java - Combine or merge all jars in one executable jar

Kind of a "simple" question here, but it seems complicated to do such a thing using Eclipse.

I have a "utils" project, in which I have developped "common" code like xml parsers, loggers, maths calculations, debug utilities and such.

This library is based on several other external libs (commons-lang-3.1, colt-1.2.0, jdom-2.0.4) to work, and it's a non-runnable JAR file (ie, there is no main(), just utility code to include in other projects).

What I want to do is, when I create the JAR file of my project, extract all external JARs (common-lang, colt, jdom) in the JAR file, in order to automatically use them on other projects.

The reason is that I don't want to re-include common-lang, colt and jdom on every projects based on my lib, but use the ones packed in my lib JAR file (and it's a way to ensure that I'll be using the same version of those libs in the projects based on my lib, too)

I know how to do that with a runnable JAR file. See for instance : How to create a jar with external libraries included in Eclipse?

But in a non-runnable JAR file :

  • all my classes are correcly exported in a correct directory structure based on the packages I created (hopefully ;-)),
  • but external JAR files are exported "as-is", so when I import my JAR in another project, those JARs (common-lang, ...) can't be seen, and I have to re-import them.

Is there a simple way to export this JAR file with a directory structure in which all external JARs files are extracted in the generated JAR file, too ?

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have you seen JarSplice?

JarSplice merge all your jars and native files into one, easy to use executable jar file via an easy to use GUI.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...