How to get flattenmapper result in ant?

Please find some targets from my ant file:

<fileset id="test-dep-jars" dir="o:/java"> <include name="junit-4.10.jar"/> <include name="easymock-3.1\easymock-3.1.jar"/> <include name="easymockclassextension-3.1\easymockclassextension-3.1.jar"/> </fileset> <target name="copy-test-deps"> <mkdir dir="${deploy.dir}"/> <copy todir="${deploy.dir}"> <fileset refid="test-dep-jars"/> <flattenmapper/> </copy> </target> <target name="jar" depends="copy-test-deps"> <jar destfile="${deploy.dir}/test-${ant.project.name}.jar" basedir="${test.classes.dir}" includes="**/*.class" filesetmanifest="skip"> <manifest> <attribute name="Class-Path" value="${ant.project.name}.jar junit-4.10.jar easymock-3.1.jar easymockclassextension-3.1.jar"/> </manifest> </jar> </target> 

My problem is that I have to specify test dependency bans twice - once when defining the test-dep-jars file set and second time when specifying the Class-Path manifest attribute created by the jar.

If I could get the result of flattenmapper, then I could use it in Class-Path as it is.

How can I get a flattenmapper result?

Thanks.

+4
source share
2 answers

Instead, I recommend using manifestclasspath :

 <manifestclasspath property="jar.classpath" jarfile="${jar.file}"> <classpath> <fileset dir="${deploy.dir}" includes="*.jar"/> </classpath> </manifestclasspath> <jar destfile="${jar.file}" basedir="${classes.dir}"> <manifest> <attribute name="Main-Class" value="${jar.main.class}" /> <attribute name="Class-Path" value="${jar.classpath}" /> </manifest> </jar> 

It will generate the correct definition of the classpath property and even work with relative paths (for example, if you have to put dependent banks in a subdirectory).

+3
source

If you want to use flattenmapper, you can use the following ...

 <pathconvert property="mf.classpath" pathsep=" "> <path refid="build.class.path" /> <flattenmapper /> </pathconvert> <manifest> <attribute name="Class-Path" value="${ant.project.name}.jar ${mf.classpath}"/> </manifest> 
+4
source

Source: https://habr.com/ru/post/1447735/


All Articles