2

I have a project with several third-party JAR files in several directories. Currently, the project uses some ant tricks to recursively include all jar files into the classpath. I want to build a deployment for another site which will include JAR'ing my own code into a single file and somehow including the other JARs that I need. Oracle claims that wildcards on the commandline will not recursively include jars. I want the deployment to work in Windows or Linux.

It seems like I have the following options:

  1. Include ant with my JAR and run the existing script.
  2. Somehow re-organize the jars to be in a single directory so I can use a wildcard in my classpath. Hopefully it won't break the third-party libraries.
  3. Manually create a big, ugly classpath.

Does anyone know of an easier way? I'm inclined to go with #1 for now.

User1
  • 39,458
  • 69
  • 187
  • 265
  • You can put the jars in one directory and include a script that builds the classpath. – Hot Licks Oct 11 '11 at 16:37
  • If a jar has a dependency on where it's located, that jar is broken--I've certainly never seen such a thing. – Dave Newton Oct 11 '11 at 16:39
  • @Dave Newton it's a feature of the jar manifest, see http://download.oracle.com/javase/tutorial/deployment/jar/downman.html – Matt Oct 11 '11 at 16:46
  • @Matt He still needs to enumerate the list of jars in the master jar. – Jagat Oct 11 '11 at 16:49
  • @Jagat edited to clarify, I was responding to the "the jar is broken" comment – Matt Oct 11 '11 at 16:51
  • @Matt And I'm saying if a *library* has a dependency on where it's located, that library is broken and a bad citizen. – Dave Newton Oct 11 '11 at 17:06
  • @DaveNewton the OP's Q suggests it is an app not a library, for which relative paths are pretty common practice – Matt Oct 11 '11 at 19:28
  • @Matt His concern was to not break the third-party libraries. If a third-party library breaks because of where it's located, it's broken. OP is building a deployable package and needs to include those libraries on the classpath. If those libraries break because of their location, those libraries are broken. – Dave Newton Oct 11 '11 at 19:31

3 Answers3

2

I'd go with #2. When you build your distribution, copy all the jars to a "lib" directory, then include them all using wildcards. I've never known a third party library to break when doing such a thing. There shouldn't be much trickery to it using ant: use copy with flatten="true" and include the fileset(s) indicating the directories/jars to recurse through.

andypandy
  • 1,117
  • 7
  • 9
0

option 4: The goal is to make you app startable simply with

java -jar your.jar

The main class and the classpath are set in the MANIFEST.MF of your.jar. Use ant to create the classpath at build time. This can be either a big, ugly, nested tree or a big, ugly flattened tree in lib.

See here, here and here for examples.

Community
  • 1
  • 1
A.H.
  • 63,967
  • 15
  • 92
  • 126
0

You can use JarJar and put everything in a single JAR file. You'll need to verify third-party licensing and distribution terms to ensure you can repackage their libraries.

Go Dan
  • 15,194
  • 6
  • 41
  • 65