I have multiple Java eclipse projects. Each of them has "jardesc" file for building jar. It's nice - double click -> finish and jar file is made. But when i have to export several jars it's a pain - i have to repeat procedure several times. Please tell me, can i use Ant script to run several "jardesc" files at once (and get several jars according to each jardesc file)? How to do it?
3 Answers
You could use the jar target to make the jars for you:
<jar destfile='destination.jar' basedir='source\dir\' /> so your build.xml would look a little like this:
<project default="makejars"> <target name="makejars"> <jar destfile="app1.jar" basedir="app1\src\" /> <jar destfile="app2.jar" basedir="app2\src\" /> <jar destfile="app3.jar" basedir="app3\src\" /> </target> </project> then just run ant in the same directory as build.xml, and the jars should be made.
Comments
Take a look at subant task in ant. You can create ant-file which would call other files to.
<subant target="create_jar1"> <fileset dir="." includes="jar2.xml"/> </subant> <subant target="create_jar2"> <fileset dir="." includes="jar1.xml"/> </subant> 1 Comment
You can use some loops to create ant parameters however there is no way to loop to create multiple jars (even with ant-commons extension), a copy & paste is the only viable solution unless you want to write an ant plugin (which doesn't really take that much 2 hours reading docs + write simple plugin)
1 Comment
for and foreach tasks