It's not a secret anymore!
The moose likes Ant, Maven and Other Build Tools and the fly likes Parameters in Java task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Parameters in Java task" Watch "Parameters in Java task" New topic

Parameters in Java task

Andrew Prinoli

Joined: Jan 11, 2007
Posts: 22
Hi guys,
The java class that I wan't to run (with java task) requires a commandline parameter : a single String character.
I know that in the build.xml I can specify attributes...but It's not possible to let the user choose...
How do I let the user insert a command line parameter???
Thanks a lot!!!

actual target
<target name="initiator" depends="compile"
description="execute app.initiator,requires config parameter">
<java classname="app.Initiator" fork="true" classpath="classes"/>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

You didn't actually say that you want the user to run Ant and have Ant run a java app, but your sample makes it look that way. You can define environment variables going to Ant in the same way that you can for any Java application, using the -Dname=value command-line construct. To make it prettier (and safer), wrap the Ant command line with a shell script/batch command file.

To get the command value to the actual java app, just define a param stanza on the Ant <java> command where the value would be substituted in the usual way:

Please check your ant manual on how to pass in parameters. I'm working from my so-called memory. But I hope you get the idea.

An IDE is no substitute for an Intelligent Developer.
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
I usually use the -Dname=value style, but also you could take a look at the Input task that prompts the user for a value.
I agree. Here's the link:
subject: Parameters in Java task
It's not a secret anymore!