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:
Click Run As and select External Tools Configuration
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.
Now if you return to the Ant view, right click and select Run As… you will get a dialog with the configurations you defined…
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




That’s a pretty neat tip. Thanks for sharing!