"jar -C" - Changing Input Directory

This section provides a tutorial example on how to 'jar --create -C ...' to change input directory when creating JAR files.

When create a new JAR file with the "jar --create" command, you can use the "-C ..." option to change the input directory from the current directory to the give directory.

The "-C ..." allows us to create a JAR file with all class files organized in a Java package directory tree.

To test this, I created the following Java source code, TempratureConvertorBean.java:

/* TempratureConvertorBean.java
 * Copyright (c) 2005 HerongYang.com. All Rights Reserved.
package com.herongyang;
public class TempratureConvertorBean {
  private double celsius = 0.0;
  private double fahrenheit = 32.0;
  public double getCelsius() {
    return celsius;
  public void setCelsius(double c) {
    celsius = c;
    fahrenheit = 1.8*c + 32.0;
  public double getFahrenheit() {
    return fahrenheit;
  public void setFahrenheit(double f) {
    fahrenheit = f;
    celsius = (f-32.0)/1.8;
  public String getInfo() {
    return new String("My TempraturConvertorBean - Version 1.00");

After compiling this source code, I got a Java package directory tree for the Java class file:

herong> mkdir .\cls

herong> javac -d .\cls TempratureConvertorBean.java

herong> tree /F .\cls

I used the "jar --create -C ..." command to create a JAR file, herong.jar:

herong> jar --create --verbose --file herong.jar -C .\cls .\com

added manifest
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/herongyang/(in = 0) (out= 0)(stored 0%)
adding: com/herongyang/TempratureConvertorBean.class(in = 806) (out= 462)

herong> jar --list --verbose --file herong.jar
     0 ... 2018 META-INF/
    66 ... 2018 META-INF/MANIFEST.MF
     0 ... 2018 com/
     0 ... 2018 com/herongyang/
   806 ... 2018 com/herongyang/TempratureConvertorBean.class

Notice that:

I deleted ".\cls" directory including class files, because all classes are stored in the herong.jar now.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 java - The Java Program Launcher

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



"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

 javadoc - The Java Document Generator

 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

 Miscellaneous Tools

 native2ascii - Native-to-ASCII Encoding Converter

 JAB (Java Access Bridge) for Windows

 Archived Tutorials


 Full Version in PDF/EPUB