Solved

Passing zero or more arguments to Ant

Posted on 2009-03-31
4
488 Views
Last Modified: 2012-05-06
Hello, after reading and experimenting, I've figured out that you can add the following line to an Ant build file to pass arguments:

<arg line="${args}"/>

The build can then be run as follows:

ant -Dargs="arg1 arg2 arg3" class

However, I was wondering how to correctly make my Ant build file support 0 arguments as well.  In other words, if -Dargs is not specified, "{$args}" will be passed as a parameter, which I don't want.  I realize I could do -Dargs="", but this seems messy and unnecessary.  What's the best way to handle this?

Thanks.
0
Comment
Question by:MasterNES
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Gibu George
ID: 24036503
Use properties instead of args and use property file to set the values
0
 

Author Comment

by:MasterNES
ID: 24041673
That could work, but when should you use properties for a program rather than command line arguments (or vice versa)?  I'm fairly new to Java and didn't know about properties.  After reading about them, I don't see when you would ever want to use command line arguments.
0
 
LVL 20

Accepted Solution

by:
Venabili earned 250 total points
ID: 24082009
Scripting :) When I need to do some script that runs on a scheduler or something like this, I do not want to depend on two files - so command line paramaters is easier. And on non-Windows environments, there is always the issue with the permissions of the properties file... And especially when you work in a heavy-networked environment (all types of shared drives and so on), it's easier to depend on one file (the script itself) than on the program managing to find the property file. And in most cases you will use the command line parameters to pass the location of the properties file :)
0
 

Author Closing Comment

by:MasterNES
ID: 31565191
Yep; that's what I ended up doing.  Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now