Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing zero or more arguments to Ant

Posted on 2009-03-31
4
Medium Priority
?
512 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

609 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