my dog learned polymorphism*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Parameters in Java task" Watch "Parameters in Java task" New topic
Author

Parameters in Java task

Andrew Prinoli
Greenhorn

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: 15950
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Carol Enderlin
drifter
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Parameters in Java task
 
Similar Threads
calling webservices
Java Screen builder depending on XML input
What target or task is running?
java program to accept user input, ant
Setting PATH env value in Ant 1.4.1