JAR & Command Line

I want to pass my jar file a command line argument.

I was thinking of executing via command prompt:

java MY_CLASS 1

where 1 is the argument I want to pass.

This doesn't work...

How do I do it properly, if possible.

Thanks

[265 byte] By [java4life87a] at [2007-11-27 11:21:08]
# 1

Use

java -classpath <fully qualified name of the jar>.jar MY_CLASS 1

assuming the class name is MY_CLASS and the parameter being passed is "1".

ChuckBinga at 2007-7-29 14:46:51 > top of Java-index,Java Essentials,Java Programming...
# 2

I did this:

java -classpath <My_Class>.jar My_Class 1

But I got the following error:

The system cannot find the specified file.

And The Jar file: My_Class.jar is located on desktop and I am in that directory when I type the above line....

java4life87a at 2007-7-29 14:46:51 > top of Java-index,Java Essentials,Java Programming...
# 3

Replace this:

<fully qualified name of the jar>.jar

with something like this:

C:\mystuff\test\My_Class.jar

and follow it with the name of the class you want to execute that's in the jar.

You should read this tutorial, also:

http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

ChuckBinga at 2007-7-29 14:46:51 > top of Java-index,Java Essentials,Java Programming...
# 4

Use java -jar jarfile [args...] , make sure you have the jar file in the classpath;

and for making your jar executable add an entry to the manifest file

Manifest-Version: 1.0

Main-Class: Fully Qualified Class Name

SabyChandraa at 2007-7-29 14:46:51 > top of Java-index,Java Essentials,Java Programming...