Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing command line arguments to ant

I am relatively new in ant, at school I have an assignment to do a build file. One of my questions is to copy to "/foldercopy" the file whose name(or path) is taken as argument for ant. I need to do something like:

ant cpfile file.txt

So ant will copy the file.txt to /foldercopy. I searched a lot on google but all I could find was something with "-Darg", but my teacher said that it's not correct. Is there any way to do it?

like image 214
André Hincu Avatar asked Jan 13 '13 23:01

André Hincu


People also ask

How do you pass an argument to an Ant build?

Discussion. If you want to pass arguments to Ant, you can enter those arguments in the Arguments box of the dialog opened by right-clicking your build file, clicking Run Ant, and clicking the Main tab. You can see that dialog in Figure 7-15 (note that you also can set the build file location and base directory here).

How do I call Ant target from command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is Antcall in build XML?

Description. Call another target within the same buildfile optionally specifying some properties (params in this context). This task must not be used outside of a target . By default, all of the properties of the current project will be available in the new project.

What is Ant build script?

Ant is a Java-based build tool created as part of the Apache open-source project. You can think of it as a Java version of make. Ant scripts have a structure and are written in XML. Similar to make, Ant targets can depend on other targets.


1 Answers

Plain command line arguments to ant are considered to be target names, so if you want to pass arguments to your target you need to use properties, via -D:

ant -Dfile=file.txt cpfile

and access the value as ${file} inside build.xml

like image 145
Ian Roberts Avatar answered Sep 28 '22 05:09

Ian Roberts