Creating a config list of classpath jars in ant
I have a list of jars in an ant task like this..
<path id="lib.path.id">
<fileset dir="${lib.dir}">
<include name="jar/*.jar"/>
</fileset>
</path>
I want to开发者_开发百科 unroll this into a config file like this..
wrapper.java.classpath.1=../lib/activation.jar
wrapper.java.classpath.2=../lib/bcel.jar
wrapper.java.classpath.3=../lib/c3p0-0.8.4.5.jar
wrapper.java.classpath.4=../lib/cglib-full-2.0.2.jar
....
How can I do this in ant?
As explained in my comment, if you are using Tanuki Service Wrapper for Java, you are not forced to list all your jar in the wrapper.conf
, you can simply indicate a path that contains all your JAR files:
wrapper.java.classpath.1=/path/to/lib/*.jar
wrapper.java.classpath.2=/any/other/lib/directory/*.jar
wrapper.java.classpath.3=/a/path/to/one/library/my-library.jar
...
In Ant you can use the pathconvert task in order to convert the path collection to a String. Then you can use it in your config file. It won't be in the exact format you specified, but it will be in a proper classpath format, ready to use for a java command.
<pathconvert targetos="unix" property="wrapper.java.classpath" refid="lib.path.id"/>
To create a properties file use the propertyfile task:
<propertyfile file="my.properties">
<entry key="wrapper.java.classpath" value="${wrapper.java.classpath}"/>
</propertyfile>
Eran hinted the right direction. I am using the ant.library.dir as an example.
<project name="util">
<property name="lib.dir" value="${ant.library.dir}"/>
<target name="gen-property-file" description="">
<path id="lib.path.id">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<pathconvert pathsep="${line.separator}wrapper.java.classpath.Number="
property="echo.path.compile"
refid="lib.path.id">
</pathconvert>
<echo file="my.properties">wrapper.java.classpath.Number=${echo.path.compile}</echo>
</target>
This snippet procudes an file my.properties:
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-antlr.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-bcel.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-bsf.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-log4j.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-oro.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32\eclipse\plugins\org.apache.ant_1.7.1.v20100518-1145\lib\ant-apache-regexp.jar
wrapper.java.classpath.Number=D:\Programme\eclipse-rcp-helios-SR1-win32
...
You can replace the .Number and the Basepath manually or with a script.
精彩评论