aspose file tools*
The moose likes Java in General and the fly likes Pass Parameter to java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pass Parameter to java application" Watch "Pass Parameter to java application" New topic
Author

Pass Parameter to java application

Angela D'souza
Ranch Hand

Joined: Jan 16, 2002
Posts: 469
Hi,
I have one java application(which has main method). Generally, if we want to pass parameter to application using command line, we type
java <Name of Application> <Parameters>
Right now, in our project we using batch file which we add some classpath and use java keyword to run an application. Now if I use batch file, how we can pass parameter to an application??? We don't want admin to open the batch file to pass parameter to an application.
Thanks,
Angela
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
in your batch file do the following:
java MyClass %1 %2 %n
where n is the number of parameters you expect to pass eg.
you java class is called MyApp and it takes 2 parameters
your batch file (say its named runme.bat) would look like this:
java MyApp %1 %2
Then whoever is running it would issue the command:
runme.bat "parameter1" "parameter2"
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Your other choices are to add a small Dialog at the beginning of your app to take in those parameters before the rest of your app fires up, OR to have the main method ask for some input from the console, which means that the user must know to go to the DOS window to enter those parameters.

This conversation has some sample code for console input.
http://www.coderanch.com/t/386991/java/java/reading-integers-System
[ October 04, 2002: Message edited by: Cindy Glass ]

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
 
subject: Pass Parameter to java application