I wouldnt start java programs via exec.
I modified the tutorial example a litte bit.
Basically you iterate with AntContrib over the JARs and start them via <java>.


Jan


/src/oata/HelloWorld.java
package oata;

public class HelloWorld {
    public static void main(String[] args) {
        // Tutorial modified for printing the current location/actual JAR
        java.net.URL location = 
HelloWorld.class.getProtectionDomain().getCodeSource().getLocation();
        System.out.println(location);
    }
}


/build.xml
<!-- based on 
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html#enhance -->
<project name="HelloWorld" basedir="." default="main">

    <property name="src.dir"     value="src"/>

    <property name="build.dir"   value="build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>
    <property name="jar.dir"     value="${build.dir}/jar"/>

    <property name="main-class"  value="oata.HelloWorld"/>



    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
    </target>

    <target name="jar" depends="compile">
        <mkdir dir="${jar.dir}"/>
        <jar destfile="${jar.dir}/${ant.project.name}.jar" 
basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
            </manifest>
        </jar>
        <!-- modification for having multiple JARs -->
        <copy file="${jar.dir}/${ant.project.name}.jar" 
tofile="${jar.dir}/${ant.project.name}2.jar"/>
        <copy file="${jar.dir}/${ant.project.name}.jar" 
tofile="${jar.dir}/${ant.project.name}3.jar"/>
        <copy file="${jar.dir}/${ant.project.name}.jar" 
tofile="${jar.dir}/${ant.project.name}4.jar"/>
    </target>

    <target name="run" depends="jar">
        <!-- modification for running multiple JARs -->
        <!-- use AntContrib for iterating over the JARs -->
        <ac:for param="jar" xmlns:ac="antlib:net.sf.antcontrib">
            <fileset dir="${jar.dir}" includes="*.jar"/>
            <sequential>
                <java jar="@{jar}" fork="true"/>
            </sequential>
        </ac:for>
    </target>

    <target name="clean-build" depends="clean,jar"/>

    <target name="main" depends="clean,run"/>

</project>

-----Ursprüngliche Nachricht-----
Von: Ravagli Virgilio [mailto:virgilio.rava...@ansaldo-sts.com] 
Gesendet: Mittwoch, 14. November 2012 11:18
An: Ant Users List
Betreff: R: R: [newbie] excute multiple jar files

Well, there are several ways to do what you want. I'll show you just one of 
these ways, I'm using it:

It's my build.xml, it's only a sample, okay ?

<?xml version="1.0"?>
<project name="Prova" basedir=".">
  <target name="run">
        <antcall>
                <target name="taskServer"/>
                <target name="taskClient"/>
        </antcall>
  </target>

  <target name="taskServer">
        <exec executable="java" spawn="true">
                  <arg line="-jar"/>
                  <arg value="EmployeeServer.jar"/>
        </exec>
  </target>
  <target name="taskClient">
        <exec executable="java" spawn="true">
                  <arg line="-jar"/>
                  <arg value="EmployeeClient.jar"/>
        </exec>
  </target>
</project>

You can use a lot of options and parameters to customize the behaviors of this 
sample build.xml.

I hope this can give you some hints

Bye
Virgilio

-----Messaggio originale-----
Da: Nam Truong Le [mailto:lenamtru...@gmail.com]
Inviato: martedì 13 novembre 2012 11.09
A: Ant Users List
Oggetto: Re: R: [newbie] excute multiple jar files

Hi,

Yes. That is what I want to do

Von meinem iPad gesendet

Am 13.11.2012 um 10:13 schrieb Ravagli Virgilio 
<virgilio.rava...@ansaldo-sts.com>:

> Hi,
> Can you make an example of what you're willing to do, please ?
> i.e. given A.jar and B.jar, you want to execute java -jar A.jar and
> java -jar B.jar from the same build.xml ?
>
> Regards,
> Virgilio
>
> -----Messaggio originale-----
> Da: lenamtru...@gmail.com [mailto:lenamtru...@gmail.com]
> Inviato: venerdì 9 novembre 2012 21.49
> A: user@ant.apache.org
> Oggetto: [newbie] excute multiple jar files
>
> Hi,
>
> do you know how to excute multiple jar files using just only one ant 
> build.xml?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional
> commands, e-mail: user-h...@ant.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional 
commands, e-mail: user-h...@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to