1

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 Main class. Am I supposed to change it to be called myapp?
  • I've been running my app with java Main compress filename. I see that now I shouldn't be using the java key. 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 compress argument I always use and the -compress one 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?

Saturn
  • 17,888
  • 49
  • 145
  • 271

1 Answers1

3

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 (or myapp.bat) and make it launch Java, passing the appropriate arguments.

As to the -compress argument, your main() takes an argv. 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?

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • Oh, so the dash has no special meaning? – Saturn Nov 24 '12 at 08:03
  • That's right. It's up to your program to interpret the command-line arguments. As far as the OS and Java are concerned, it makes no difference if any of them start with a dash. – NPE Nov 24 '12 at 08:04