ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matèrne, Jan (RZF, SG 481) <>
Subject AW: R: [newbie] excute multiple jar files
Date Fri, 23 Nov 2012 07:02:10 GMT
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>.


package oata;

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

<!-- based on -->
<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 name="compile">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}"/>

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

    <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"/>
                <java jar="@{jar}" fork="true"/>

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

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


-----Ursprüngliche Nachricht-----
Von: Ravagli Virgilio [] 
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">
                <target name="taskServer"/>
                <target name="taskClient"/>

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

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


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


Yes. That is what I want to do

Von meinem iPad gesendet

Am 13.11.2012 um 10:13 schrieb Ravagli Virgilio <>:

> 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: []
> Inviato: venerdì 9 novembre 2012 21.49
> A:
> 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: For additional
> commands, e-mail:

To unsubscribe, e-mail: For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message