Solved

Passing zero or more arguments to Ant

Posted on 2009-03-31
4
495 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat administrtor 12 61
use lov values 2 63
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 1 36
add projects t working set in maven 2 24
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

830 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