Option '-jar' - Specifying Executable JAR Files

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

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!

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

'java' - The Java Program Launcher

 'java' - Java Launching Command and Options

 Launching Hello.java - My First Java Program

 Option "-classpath" - Specifying Class Path

Option '-jar' - Specifying Executable JAR Files

 Option '-X' - Specifying Non-Standard Options

 'javaw' - Launching Java Programs without Console

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 PDF Printing Version