Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Ant build.xml

  • 19-09-2005 09:44AM
    #1
    Registered Users, Registered Users 2 Posts: 194 ✭✭


    I need to pass command-line arguments into my build.xml

    Any idea how to do this?

    I know there's an <arg> tag but afaik that's used for passing arguments to an executable.

    Cheers

    -pb


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    http://ant.apache.org/manual/

    The two you are looking for are...

    ant build.xml -D<property>=<value>

    Creates a property with set value. If you want to load a properties file then..

    ant build.xml -propertyfile <name>

    Personally I create a properties file and reference it in the build xml like so..

    <property file="build.properties"/>

    In that file I put all my properties.

    I also tell it to reference the system properties (SET) with this..
    <property environment="env"/>

    Then reference System environment variables like so
    ${env.PATH}
    ${env.CLASSPATH}


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    Cheers Hobbes,

    A little bit more detail on what I'm doing:

    I have a CommandLineParser class which defines 3 command-line options(eg. -a, -b, -c).

    I then have a target in my build.xml - "my-target".

    So in the cmd, when I want to build the target I want to be able to use the following:

    ant my-target -a argument1

    argument1 will be used to set a configuration variable in the application.

    The CommandLineParser is executed within "my-target".

    Is this the correct flow in order to achieve the above? Can I pass argument1 from "my-target" to the (String[] args) of CommandLineParser's main method?



    Cheers


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    shouldn't it be ...

    ant build.xml my-target -Dcmdarg="-a argument1"

    then run your command line parser with ${cmdarg} as the argument.


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    Cheers Hobbes,

    I'll give it a go so.....I'm a bit flaky on Ant so just trying to piece it together.

    -pb


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    Ok,

    So I got that working Hobbes, nice one.

    Next Q is this:

    I now have a build.xml and two forked scripts build1.xml and build2.xml.

    How can I execute the child scripts from the main script build.xml?

    Is it a case of using:
    <java classname="build2 class name" dir="${YYY}/.." fork="true" failonerror="true"><classpath>
    <pathelement location="${XXX}"/>
    <fileset dir="${TTT}" includes="*.jar" excludes="ant.jar" />
    </classpath>	
    </java>
    

    Cheers

    -pb


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    use ANT or ANTCALL commands. Try the manual its pretty good.

    example:

    <ant antfile="build2.xml" dir="directory"/>


  • Registered Users, Registered Users 2 Posts: 194 ✭✭pbarry


    Cool,

    I've been crawling through the manual but its hard to find what you need when you don't know what you're looking for!

    appreciate it hobbes..........


Advertisement