passing command line arguments thru ant

Discussion in 'Java' started by jimgardener, Oct 20, 2008.

  1. jimgardener

    jimgardener Guest

    hi
    i have a java class which takes in 3 arguments,ie a foldername string,
    an imagename string,and an integer.From command line i run this like
    java myapp.PatternMaker myfolder samples/image1.jpg 5

    I wanted to do this thru ant buildfile. so i put a target like

    <target name="run" depends="compile">
    <java classname="myapp.PatternMaker">
    <classpath>
    <pathelement location="${build}"/>
    <pathelement path="mylib/somegraphics.jar"/>
    </classpath>
    <arg line="${myfolder} ${samples}/image1.jpg 5"/>

    </java>
    </target>


    This lets me call ant run to run the program.But i have a need to run
    the program with diff image names and diff integer values as arguments.
    (The locations of myfolder and samples directories do not change),I
    may need to run the code as

    java myapp.PatternMaker myfolder samples/image2.jpg 8

    Can someone tell me how i can do this ?I am a beginner to ant ..i
    would like to have something like
    ant run image2.jpg 8 to run the program with the above arguments.I
    couldn't quite figure out how to do this.Can someone help?

    thanks
    jim

    p.s: also i saw some warnings in ant manual to avoid usage of
    <arg line ...Is there a better way i can pass the arguments?
    jimgardener, Oct 20, 2008
    #1
    1. Advertising

  2. jimgardener <> wrote in news:2eb9ebbc-43ca-4d4f-
    :

    > hi
    > i have a java class which takes in 3 arguments,ie a foldername string,
    > an imagename string,and an integer.From command line i run this like
    > java myapp.PatternMaker myfolder samples/image1.jpg 5
    >
    > I wanted to do this thru ant buildfile. so i put a target like
    >
    ><target name="run" depends="compile">
    > <java classname="myapp.PatternMaker">
    > <classpath>
    > <pathelement location="${build}"/>
    > <pathelement path="mylib/somegraphics.jar"/>
    > </classpath>
    > <arg line="${myfolder} ${samples}/image1.jpg 5"/>
    >
    > </java>
    > </target>
    >
    >
    > This lets me call ant run to run the program.But i have a need to run
    > the program with diff image names and diff integer values as arguments.
    > (The locations of myfolder and samples directories do not change),I
    > may need to run the code as
    >
    > java myapp.PatternMaker myfolder samples/image2.jpg 8
    >
    > Can someone tell me how i can do this ?I am a beginner to ant ..i
    > would like to have something like
    > ant run image2.jpg 8 to run the program with the above arguments.I
    > couldn't quite figure out how to do this.Can someone help?
    >
    > thanks
    > jim
    >
    > p.s: also i saw some warnings in ant manual to avoid usage of
    ><arg line ...Is there a better way i can pass the arguments?
    >


    I'm not good with ant either, but I would try something like this

    <target name="run" depends="compile">
    <java classname="myapp.PatternMaker">
    <classpath>
    <pathelement location="${build}"/>
    <pathelement path="mylib/somegraphics.jar"/>
    </classpath>
    <arg value="${myfolder} />
    <arg value=${samples}/image1.jpg />
    <arg value="1" />
    <java classname="myapp.PatternMaker">
    <classpath>
    <pathelement location="${build}"/>
    <pathelement path="mylib/somegraphics.jar"/>
    </classpath>
    <arg value="${myfolder} />
    <arg value=${samples}/image1.jpg />
    <arg value="2" />
    </java>
    <java classname="myapp.PatternMaker">
    <classpath>
    <pathelement location="${build}"/>
    <pathelement path="mylib/somegraphics.jar"/>
    </classpath>
    <arg value="${myfolder} />
    <arg value=${samples}/image1.jpg />
    <arg value="3" />
    <!-- and so on... -->
    </java>
    </target>
    Donkey Hottie, Oct 20, 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. Replies:
    4
    Views:
    1,693
    Terry Hancock
    Apr 23, 2005
  2. =?iso-8859-1?q?Luis_M._Gonz=E1lez?=

    Passing arguments to a command line from a python script

    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=, Mar 19, 2007, in forum: Python
    Replies:
    6
    Views:
    2,647
    =?iso-8859-1?q?Luis_M._Gonz=E1lez?=
    Mar 20, 2007
  3. mcanjo
    Replies:
    11
    Views:
    510
    Bror Johansson
    Apr 6, 2010
  4. THTB
    Replies:
    0
    Views:
    173
  5. Max Williams
    Replies:
    3
    Views:
    155
    Robert Klemme
    Jan 6, 2009
Loading...

Share This Page