5

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 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Is this suposed a call to another ant thask that build the jar or is this a call to jardesc. Plz be more clear.
-2

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

ant-contrib has for and foreach tasks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.