2

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

Community
  • 1
  • 1
adrien.pain
  • 443
  • 2
  • 11
  • 18
  • Possible duplicate question http://stackoverflow.com/questions/528007/eclipse-java-export-jar-include-referenced-libraries-without-fatjar?rq=1 – greedybuddha May 07 '13 at 15:30
  • yep, I already saw that question on stackoverflow, and I'm running Eclipse Helios (Version: 3.6.1.r361_v2010090), so it seems that my Eclipse version should have this option. Unfortunately, it's only with runnable JAR files – adrien.pain May 07 '13 at 15:41
  • Use Maven of course, via the 'maven-jar-plugin'. To actually execute the .jar as "runnable", use this batch script: https://gist.github.com/djangofan/4144970 – djangofan May 07 '13 at 15:58
  • This Will cause you pain in the long run. Much better idea to modularise and use dependencies. Look at maven or ant ivy. – Thorbjørn Ravn Andersen May 07 '13 at 16:00
  • Also, why not just make it runnable so you can use the tools you know? – Thorbjørn Ravn Andersen May 07 '13 at 16:03
  • @ThorbjørnRavnAndersen : yep, I'll mark my question as resolved, as I've just create a runnable JAR file with a dummy main(). – adrien.pain May 07 '13 at 16:07
  • @ThorbjørnRavnAndersen : but why that way of doing my own common lib with specific exeternal JARs files will "cause me pain in the long run" ? – adrien.pain May 07 '13 at 16:08
  • Comes the day you have many different versions of your code which you need to support. If this is just for fun, then you're fine. – Thorbjørn Ravn Andersen May 07 '13 at 16:13
  • @ThorbjørnRavnAndersen : still don't understand, as I already worked on several big projects, and I prefer to ensure that all projects use the same common lib with common source code, instead of its own version, specificities and such. We may have different points of view, probably ;) – adrien.pain May 07 '13 at 20:37
  • I understand that. It is just my experience that third-party jars get maintained so you need to update your jar regularily and manually, and that becomes cumbersome if you have several versions in play over time. – Thorbjørn Ravn Andersen May 07 '13 at 22:49
  • @ThorbjørnRavnAndersen : agreed, though – adrien.pain May 07 '13 at 23:40

1 Answers1

3

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

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
  • Didn't know about that tool, I'm checking it, seems to do what I want to do. But I'd like to create/deploy my JAR files from within Eclipse, if possible. I'm still checking if it's possible or not... – adrien.pain May 07 '13 at 15:43