Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Is it possible to pass parameter directly to application through Ant?

800808Jan 31 2012 — edited Feb 7 2012
Hi All,

I am wondering whether it is possible to pass parameter to a Java program directly when executed through Ant. Below is an example of what I am referring to:
    public class Fly {
        public static void main(String[] args) throws IOException {
        
            if (args[0].matches("(?:NORTH|SOUTH|EAST|WEST|north|south|east|west)")) {
                .......
            }
        }
    }
It is then possible to run Fly and supply the parameter using the following syntax after having successfully built it using Netbeans 7.0.1 & Java 1.7.0 on Windows 7:

java -jar C:/USERS/Jack/Fly/dist/Fly.jar SOUTH

However, I am looking for the equivalent command line to invoke the same program through Ant below:

C:\USERS\Fly>ant run SOUTH

Instead, I will need to define ${direction} in the Ant build file before passing the value as property:

ant run -Ddirection=SOUTH

This resulted in the following build run error:

BUILD FAILED
Target "SOUTH" does not exist in the project "Fly".

In short, I am looking for a way to pass the parameter directly to the Java application when running the application using Ant without having to customise the build
file by defining the parameter as property.

Thanks in advance,

Jack
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2012
Added on Jan 31 2012
12 comments
830 views