File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass Parameter to java application

 
Angela D'souza
Ranch Hand
Posts: 469
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic