ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: How to call an ant script with parameters?
Date Thu, 27 Oct 2005 09:59:21 GMT
Use properties:
ant -f MyAntScript.xml MyTarget -Dparam1=MyParameter1 -Dparam2=MyParameter2 
Access in Ant: ${param1} ${param2}

see also
  passing parameters to ant

I think I had done something ... yes in 2003. 
Mmh - maybe ...


Here the 2003-code :-) But works with Ant 1.6 also.

-- ant2.bat --8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
@echo off

if "%1"=="process" goto process
goto normal

set opts=
set i=1

if "%1"=="" goto run
set opts=%opts% -Dargs.%i%=%1
set /A "i+=1"
goto loop

call ant process %opts%
goto end

call ant %*

-- build.xml -8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
<project default="main">
    <target name="main">

    <target name="process">
            1 = ${args.1}
            2 = ${args.2}
            3 = ${args.3}
            4 = ${args.4}
            5 = ${args.5}
            6 = ${args.6}
            7 = ${args.7}
            8 = ${args.8}
            9 = ${args.9}
           10 = ${args.10}
-- test -8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----8-<--
Buildfile: build.xml

     [echo] main

Total time: 0 seconds
C:\ant\anttests\wrapperscript>ant2 hello world
Buildfile: build.xml

Target `hello' does not exist in this project.

Total time: 0 seconds
C:\ant\anttests\wrapperscript>ant2 process hello world
Buildfile: build.xml

     [echo]             1 = hello
     [echo]             2 = world
     [echo]             3 = ${args.3}
     [echo]             4 = ${args.4}
     [echo]             5 = ${args.5}
     [echo]             6 = ${args.6}
     [echo]             7 = ${args.7}
     [echo]             8 = ${args.8}
     [echo]             9 = ${args.9}
     [echo]            10 = ${args.10}

Total time: 0 seconds


>-----Urspr√ľngliche Nachricht-----
>Von: Remo Liechti [] 
>Gesendet: Donnerstag, 27. Oktober 2005 11:21
>An: Ant Users List
>Betreff: How to call an ant script with parameters?
>Hi all
>I didnt find an answer to this in the documentaion or in the 
>To run a ant script, I have to call it like this:
>Ant -buildfile MyAntScript.xml MyTarget
>I call my ant script using batch files on windows. Now I need 
>to set some parameters to the ant script dynamicly, like:
>Ant -buildfile MyAntScript.xml MyTarget MyParameter1 MyParameter2
>And so on. How do I access such parameters inside of 
>MyAntScript.xml? Is it possible?
>Cause of ant's syntax, MyParameter1 and 2 would be another target... :/
>This message may contain legally privileged or confidential 
>information and is therefore addressed to the named persons only. 
>The recipient should inform the sender and delete this 
>message, if he/she is not named as addressee. 
>The sender disclaims any and all liability for the integrity 
>and punctuality of this message. 
>The sender has activated an automatic virus scanning by 
>Messagelabs, but does not guarantee the virus free 
>transmission of this message.
>To unsubscribe, e-mail: For 
>additional commands, e-mail:

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

View raw message