how to pass argument values to ant

Discussion in 'Java' started by harryos, Nov 3, 2008.

  1. harryos

    harryos Guest

    hi
    i have an ant buildfile in which i need to run java with different
    arguments

    <target name="runwith4andImage2" depends="jar">
    <java fork="true" classname="${main-class}">
    <classpath>
    ...
    </classpath>
    <arg value="${folder1}" />
    <arg value="${folder2}/image2.jpg" />
    <arg value="4" />
    </java>
    </target>

    <target name="runwith7andImage1" depends="jar">
    <java fork="true" classname="${main-class}">
    <classpath>
    ...
    </classpath>
    <arg value="${folder1}" />
    <arg value="${folder2}/image1.jpg" />
    <arg value="7" />
    </java>
    </target>

    ....
    here i think it will be better to pass the arguments image1.jpg and 7
    along with ant call and use those arguments to set arg values inside
    the target.I went thru the docs but I couldn't figure out how to do
    it.
    in short i need something like
    >>ant run image1.jpg 7 sothat i can use the arguments from inside a single target run


    can someone tell me how i can do this?
    thanks
    harry
     
    harryos, Nov 3, 2008
    #1
    1. Advertising

  2. harryos <> wrote:
    > in short i need something like
    >>>ant run image1.jpg 7 sothat i can use the arguments from inside a single target run


    Just recently I had the same problem, and didn't find
    a satisfactory solution, myself.

    If in your case the number of arguments is constant,
    (the image name and a number), then you can help yourself
    with properties. Your ant-invocation then looks like
    this:

    ant -Dfile=image1.jpg -Dnum=7 run

    (which you can wrap in a shell script)
    and the build.xml would contain something like this:

    <java ...>
    <arg value="${file}">
    <arg value="${num}">
    </java>

    PS: I haven't tested it.
     
    Andreas Leitgeb, Nov 3, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bedford
    Replies:
    6
    Views:
    2,245
  2. john martin
    Replies:
    2
    Views:
    2,221
    john martin
    Apr 7, 2005
  3. Replies:
    1
    Views:
    511
    Larry
    Mar 7, 2006
  4. Ben Kial
    Replies:
    1
    Views:
    661
    Eric Enright
    Nov 15, 2004
  5. Replies:
    6
    Views:
    880
Loading...

Share This Page