RSS Forums RSS

Interpreting JAR's launched with parameters

Please support our Java advertiser: Programming Forums
Reply
Posts: 124
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Interpreting JAR's launched with parameters

  #1  
Jan 6th, 2009
Hey guys,
I am trying to get some code to interpret a parameter determined by a JAR file.

IE.
C:\user\myProgram.jar 500
I want to know how to transfer 500 over to the program. I googled it, and most of the stuff that came up was extremely difficult to understand.

Thanks PO
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,957
Reputation: masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold 
Solved Threads: 198
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: Interpreting JAR's launched with parameters

  #2  
Jan 7th, 2009
To tell you the truth, I don't know what you mean "interpret a parameter determined by a JAR file".

If it is simply to be an argument on the command line, then, of course, args[0].
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Posts: 124
Reputation: PhiberOptik is an unknown quantity at this point 
Solved Threads: 4
PhiberOptik's Avatar
PhiberOptik PhiberOptik is offline Offline
Junior Poster

Re: Interpreting JAR's launched with parameters

  #3  
Jan 7th, 2009
args[0] ?

Sorry i am confused, here I will give you a small rundown of the program. I use a program to automatically log myself into Steam. With steam you can launch their games by saying C:\Steam\steam.exe -login username password -applaunch 500 and of course the login and application vary between games. So I have a bunch of icons on my desktop that go to a JAR that logs me into steam automatically, but then I have to launch the game from inside of steam, so I want to know how to launch a JAR and have the jar grab the parameter. Basically I want to say C:\user\thatProgram.jar -500 and have the program look for the parameter and if it's there make it a int inside of my program.

Thanks Jon
History will be kind to me for I intend to write it.
---------------------------------- Sir Winston Churchill
Reply With Quote  
Posts: 1,144
Reputation: stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light stephen84s is a glorious beacon of light 
Solved Threads: 121
Featured Poster
stephen84s's Avatar
stephen84s stephen84s is offline Offline
Veteran Poster

Re: Interpreting JAR's launched with parameters

  #4  
Jan 7th, 2009
Now if you have ever written a main, in your Java program, we write it as :-
  1. public static void main(String args[]) {

Here the args, is an array containing the parameters you provided at the command line.

Consider the following example :-
  1. public class CommandLineArgEx {
  2.  
  3. public static void main(String[] args) {
  4. for(int i=0;i<args.length;i++) {
  5. System.out.println("Argument Number " + (i+1) + " : " + args[i]);
  6. }
  7. }
  8.  
  9. }
  10.  

Following would be the output that you will get :-

stephen@steve:~/Development/java/daniweb> java CommandLineArgEx ABC Bcd Efg
Argument Number 1 : ABC
Argument Number 2 : Bcd
Argument Number 3 : Efg
stephen@steve:~/Development/java/daniweb>

So as you see whatever is passed via the command line, is stored in the args[] String array.
Although I have never tried it with a JAR, I do not see why it should not work.
Last edited by stephen84s : Jan 7th, 2009 at 1:12 pm.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

"How to ask questions the smart way ?"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Java Forum
Views: 522 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:43 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC