Java Tools Tutorials - Herong's Tutorial Examples - v6.21, by Dr. Herong Yang
"java -jar" - Specifying Executable JAR File
This section provides a tutorial example on how to use the '-jar' option for the 'java' tool to specify an executable JAR file.
In order to use the "java -jar" option, we need to create a JAR file with a "Main-Class" attribute in the manifest file.
Here is what I did to create a JAR file, and launch it with the "-jar" option.
First I created a manifest file, hello.fs, using a text editor. The extra blank line at the end of the file is important. Keep it:
Then I created an executable JAR file, hello.jar, with Hello.class and hello.fs:
herong> javac Hello.java herong> jar -cvmf hello.fs hello.jar Hello.class added manifest adding: Hello.class(in = 416) (out= 285)(deflated 31%)
Finally, I launched the Hello.class program included in the executable JAR file:
herong> java -jar hello.jar Hello world!
Table of Contents