Passing Arguments To Ant Using Eclipse

Over the last few days I’ve been reworking one of my build files and needed to be able to pass in an argument at run time, which is easy to do using the command line.  But I became curious if there was any way to do it running the script within Eclipse.

Turns out it was easy.

Crank up the Ant view and right click on your build file:

Run As

Click Run As and select External Tools Configuration

External Tool Dialog

Click the Main tab and enter your Ant arguments in the arguments dialog. What is neat is you can create multiple configurations so you can run your build easily with different arguments.  Enter a friendly name and notice it show up on the file list on the left.

You can then right click on that name and duplicate it and then modify the arguments in the new config.

Duplicate

Now if you return to the Ant view, right click and select Run As… you will get a dialog with the configurations you defined…

Options

My Ant target looks like:


And we’ll replace ${myValue} with an argument I defined in my configuration above (-DmyValue=”Jim Likes Ant”). Running my two options I defined will output


Buildfile: D:\workspace\ant\helloworld-1.xml
helloworld:
[echo] Hello World Jim Likes Ant
BUILD SUCCESSFUL
Total time: 122 milliseconds

Buildfile: D:\workspace\ant\helloworld-1.xml
helloworld:
[echo] Hello World Jim Hates Ant
BUILD SUCCESSFUL
Total time: 122 milliseconds
Recent Related Posts

One thought on “Passing Arguments To Ant Using Eclipse

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>