I’m very new to all Java related programming. For a school assignment, I’ve created my Java application using BlueJ. Apparently, the application should be able to run from the command prompt with the following line:
myapp -compress fileName
Honestly, I don’t have the slightest idea about how to setup such:
- My application has a
Mainclass. Am I supposed to change it to be calledmyapp? - I’ve been running my app with
java Main compress filename. I see that now I shouldn’t be using thejavakey. But of course, as it is now, it won’t work if I remove it. How can I run the app without it? - Is there a difference between having the
compressargument I always use and the-compressone they tell me? Is that dash (–) any special?
Looking at this page: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html, it seems to insist that to run my program I do need to use the java key. And the dash seems to be used for something called options – there are standard and non-standard. However, there doesn’t seem a way to make a “custom” one (-compress).
So my question is, how can I run my application with the above format?
The easiest way it to create a one-line shell script (if you’re using Unix) or a one-line batch file (if you’re using Windows). Call it
myapp(ormyapp.bat) and make it launch Java, passing the appropriate arguments.As to the
-compressargument, yourmain()takes anargv. You’ll need to examine that to figure out what arguments have been passed to your program. You can either code everything yourself (very easy in your case), or use an existing framework:How to parse command line arguments in Java?