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
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
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".
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....
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
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