?
Solved

Passing zero or more arguments to Ant

Posted on 2009-03-31
4
Medium Priority
?
507 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

770 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