• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pass Parameter to java application

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
https://coderanch.com/t/386991/java/java/reading-integers-System
[ October 04, 2002: Message edited by: Cindy Glass ]
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic