Using Ant to create multiple jars

I have multiple Java eclipse projects. Each of them has a "jardesc" file to create a jar. That's good - double click -> finish and jar file. But when I have to export multiple cans it is a pain - I have to repeat the procedure several times. Please tell me if I can use an Ant script to run multiple jardesc files at once (and get multiple jars according to each jardesc file)? How to do it?

+3


source to share


3 answers


Take a look at the task subant

in ant. You can create an ant file that will call other files.



    <subant target="create_jar1">
        <fileset dir="." includes="jar2.xml"/>
    </subant>
    <subant target="create_jar2">
        <fileset dir="." includes="jar1.xml"/>
    </subant>

      

+1


source


You can use the jar target to create the jars for you:

    <jar destfile='destination.jar' basedir='source\dir\' />

      

so your build.xml file will look something 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 done.

+3


source


You can use some loops to create ant options, however, it is not possible to create a loop to create multiple jars (even with the ant -commons extension) copy and paste is the only viable solution if you don't want to write an ant plugin (actually not much 2 hours of reading documents + writing a simple plugin)

-2


source







All Articles