"jar --create" - Creating New JAR File

This section provides a tutorial example on how to create a JAR file with the 'jar --create' command.

In order to create a JAR file of Java class files, I wrote the following Java source file, Hello.java, first:

class Hello {
   public static void main(String[] a) {
      System.out.println("Hello world!");   
   }
}

Then I compiled the Java source file to create the Java class file:

herong> javac Hello.java

herong> dir Hello.*
   416 Hello.class
   116 Hello.java

After that I created my first JAR file, hello.jar, with Hello.class, using the "jar --create" command:

herong> jar --create --verbose --file hello.jar Hello.class
added manifest
adding: Hello.class(in = 416) (out= 285)(deflated 31%)

herong> dir Hello.*
   416 Hello.class
   739 hello.jar
   116 Hello.java

Notice that I used:

"jar" command also supports options written in the old short format. For example, the following two commands use option short format doing the same job as above:

herong> jar cvf hello.jar Hello.class
added manifest
adding: Hello.class(in = 416) (out= 285)(deflated 31%)

herong> jar -c -v -f hello.jar Hello.class
added manifest
adding: Hello.class(in = 416) (out= 285)(deflated 31%)

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

jar - The JAR File Tool

 JAR - Java Archive File Format

 jar - JAR File Tool Command and Options

"jar --create" - Creating New JAR File

 "jar --list" - Listing Files in JAR File

 "jar --extract" - Extracting Files from JAR File

 Managing JAR Files with WinZIP

 META-INF/MANIFEST.MF - JAR Manifest File

 Adding META-INF/MANIFEST.MF to JAR Files

 "jar -C" - Changing Input Directory

 Using JAR Files in Java Class Paths

 "jar --update" - Updating Class Files in JAR

 "jar --main-class" - Making JAR File Executable

 Creating Module JAR File

 "jar --module-version" - Updating Module Version in JAR

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 java - The Java Program Launcher

 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

 jrunscript - Script Code Shell

 serialver - serialVersionUID Generator

 native2ascii - Native-to-ASCII Encoding Converter

 Outdated Tutorials

 References

 Full Version in PDF/EPUB