开发者

Recursively including jars into the classpath

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 i开发者_运维百科nclude 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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜