Solved

Passing zero or more arguments to Ant

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

705 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