开发者

What are some tips on shortening the classpath in ant?

开发者 https://www.devze.com 2023-04-01 08:49 出处:网络
When deploying my application on a Hudson Server (windows machine) , I\'m having problems calling java.exe because my class-path is too long -- Windows taps out after certain length.

When deploying my application on a Hudson Server (windows machine) , I'm having problems calling java.exe because my class-path is too long -- Windows taps out after certain length.

The classpath is basically hundreds of Jar files separated by semicolons

Assume the following classpath would be too large if each jar is开发者_运维技巧 explicitly listed in the classpath:

<path id="classpath.project">
    <fileset dir="lib" includes="**/*.jar" />
</path>

What can I do in ant to shorten my classpath?


Since Java 6 supports wildcards in the classpath. Specifically it supports using * to refer to all jar files in a given directory (note: not *.jar!):

Using * as the classpath means "all jar files in the current directory" and using lib/* means "all jar files in the directory lib/".

Unless you have tons of directories, this should be sufficient. I don't know how to make use of that fact from Ant, however.


You can google for OneJar. If you want to do it yourself, then generate an "empty" jar file that only has a manifest. Add a "Class-Path: a.jar, another.jar, bla-blub.jar" line containing all needed jars to the manifest. (Google for "manifest Class-Path") (can be done with ant) Provided that all jars are deployed aas usually you now only need your "empty" jar file on the classpath, as the JVM will now use the manifest to find all other jars.

0

精彩评论

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

关注公众号