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

Main-Class: Hello

Then I created an executable JAR file, hello.jar, with Hello.class and hello.fs:

C:\herong>javac Hello.java

C:\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:

C:\herong>java -jar hello.jar
Hello world!



 

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

java - The Java Program Launcher

 java - Program Launching Command and Options

 Launching Hello.java - My First Java Program

 "java -classpath" - Specifying Class Path

"java -jar" - Specifying Executable JAR File

 "java -X" - Specifying Non-Standard Options

 "java --list-modules" - Listing Modules in JDK

 "java --describe-module" - Printing Module Definition

 "java --module" - Launching Program from Module

 "java --module" - Launching Program from Module JAR

 javaw - Launching Java Programs without Console

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB