Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Ant build.xml

Options
  • 19-09-2005 9:44am
    #1
    Registered Users 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 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 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 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 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 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 Posts: 21,264 ✭✭✭✭Hobbes


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

    example:

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


  • Registered Users 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