Creating a JAR from the Command Prompt

Although JClass JarMaster uses a Swing-based GUI to visually aid you with JAR creation, you still have the option to create JARs from the command prompt. While this is similar to using the JDK's jar command, you still have all the functionality that JarMaster offers (namely, automatically including dependencies of all specified class files).

Note: In order for JarMaster to run from the command prompt, your CLASSPATH must point to the JarMaster JAR file. The proper entry should already have been added to your CLASSPATH environment variable when you installed JClass JarMaster.

To run JarMaster at the command prompt, type:

java com.klg.jclass.jarmaster.JarMaster

Of course, you need to append options to this command in order to actually build, list, or modify JARs. (Note: As you type in a lengthy list of JarMaster options, you may be limited with the number of characters you can enter in the command prompt, depending on your operating environment.)

JAR Creation Options
The options available when creating a JAR from the command prompt are similar to those addressed when using JarMaster's Wizard. In one line, you can:

  name and create the JAR   -c <JAR name>
  remove all default exclusions (java/, javax/, com/sun/java/)   -clear
  set the archive compression level: any digit between 0 (lowest) and 9 (highest and default)   -level <compression>
  include manifest files: using this option copies, from the included manifest file(s) to the new JAR manifest file, any manifest entries for classes that you archive in the new JAR   -m <manifest file>
  specify a main class for an executable JAR: using this option will determine which main class to run when the JAR file is executed   -mainclass
  specify a search path to use to search for dependencies (by default, the CLASSPATH is used): using this option will allow a path other than the default CLASSPATH to be set as the search path   -searchpath
  exclude entire packages   -x <package name>
  create an archive without a manifest entry (that is, creates a ZIP file)   -z <JAR name>

When creating the JAR, you can list as many classes and packages as you want, separating each reference with a space. If you want to include multiple manifest files, or exclude multiple packages, you need to set the appropriate command option for each instance. This will be demonstrated in some of the examples found below.

Other JAR Options
In addition to creating JARs, you can also perform other tasks with the JarMaster command. Using the appropriate option, you can:

  compare two JARs and output the differences   -compare <JAR name 1> <JAR name 2>
  call up a list of command line options   -help
  list the contents of a JAR   -l <JAR name>
  update a JAR with files found in the CLASSPATH   -update <JAR name>
  list the detailed contents of a JAR: name, size, compressed size, and date   -v <JAR name>

Example: Building a JAR (Part 1)
Building a JAR from the command prompt is not difficult; you just need to ensure that all the options you enter are accurate. As a basic example, follow this complete JarMaster command (which you would enter at the command prompt as one line):

java com.klg.jclass.jarmaster.JarMaster -x package/product1/util -c d:\lib\MyJar1.jar package/product1

 
java com.klg.jclass.jarmaster.JarMaster
  executes JarMaster
 
-x package/product1/util
  excludes the fictitious product1/util package (referencing it by package path); any dependencies found here will not be included in the JAR
 
-c d:\lib\MyJar1.jar
  creates a JAR named MyJar1.jar in the lib directory
 
package/product1
  referencing by package path, this statement includes all product1 classes (minus its util package), as well as all of their direct and indirect dependencies
 
Although this command would create a complete JAR, it would not include any manifest files. Additionally, since you did not specify the compression level, it is automatically set to the default (level 9).

Example: Building a JAR (Part 2)
Adding to the previous example, the following JAR command includes manifest files, and includes files in the JAR by referencing specific classes in addition to entire packages. Again, follow this complete JarMaster command (which would be entered as one line at the command prompt):

java com.klg.jclass.jarmaster.JarMaster -m d:\package\product1\manifest.txt -m d:\package\product2\manifest.txt -x package/product1/util -c d:\lib\MyJar2.jar package/product1 package/product2/Foo.class package/product3/Foo.class

 
java com.klg.jclass.jarmaster.JarMaster
  executes JarMaster
 
-m d:\package\product1\manifest.txt
-m d:\package\product2\manifest.txt
  includes any relevant manifest entries from the two manifest files for product1 and product2, which are referenced by their absolute paths
 
-x package/product1/util
  excludes the fictitious product1/util package, referencing it by package path; any dependencies found here will not be included in the JAR
 
-c d:\lib\MyJar2.jar
  creates a JAR named MyJar2.jar in the lib directory
 
package/product1
package/product2/Foo.class
package/product3/Foo.class
  includes all product1 classes (referencing it by package path), product2's Foo.class, product3's Foo.class, as well as all of their direct and indirect dependencies
 
As with the previous example, since you did not specify the compression level, it is automatically set to the default (level 9).

Example: Building a JAR (Part 3)
This example demonstrates the use of all JAR creation options at the command prompt. Unlike the previous two examples, the following command (which would be entered as one line at the command prompt) sets a compression level, and removes the default exclusions.

java com.klg.jclass.jarmaster.JarMaster -level 5 -m d:\package\product1\manifest.txt -m d:\package\product2\manifest.txt -m d:\package\product3\manifest.txt -clear -x package/product1/util -x package/product2/util -c d:\lib\MyJar3.jar package/product1 package/product2 package/product3/Foo.class

 
java com.klg.jclass.jarmaster.JarMaster
  executes JarMaster
 
-level 5
  sets the compression ratio to 5 (default and highest level is 9)
 
-m d:\package\product1\manifest.txt
-m d:\package\product2\manifest.txt
-m d:\package\product3\manifest.txt
  includes any relevant manifest entries from the three manifest files for product1, product2, and product3, which are referenced by their absolute paths
 
-clear
  removes all the default exclusions (that is, includes them in your JAR)
 
-x package/product1/util
-x package/product2/util
  excludes the fictitious util packages from product1 and product2, referencing them by their package paths; any dependencies found here are not included in the JAR
 
-c d:\lib\MyJar3.jar
  creates a JAR named MyJar3.jar in the lib directory
 
package/product1
package/product2
package/product3/Foo.class
  referencing by package paths, this statement includes all product1 and product2 classes (minus their util packages), in addition to product3's Foo.class, as well as all of their direct and indirect dependencies
 

Example: Listing the contents of a JAR
The following JarMaster command (entered as one line at the command prompt) lists the contents of a specified JAR:

java com.klg.jclass.jarmaster.JarMaster -l d:\package\product1\product1.jar

 
java com.klg.jclass.jarmaster.JarMaster
  executes JarMaster
 
-l package/product1/product1.jar
  points to, and gives the JAR name, referencing it by package path

If the correct JAR name and path were supplied, JarMaster will list the complete contents of the JAR, sorted by package structure.

Example: Comparing the contents of two JARs
The following JarMaster command (entered as one line at the command prompt) displays a list of files, based on a comparison between two JARs.

 
java com.klg.jclass.jarmaster.JarMaster -compare d:\package/product1/product1.jar d:\package/product2/product2.jar

java com.klg.jclass.jarmaster.JarMaster
  executes JarMaster
 
-compare
  indicates that the following JARs are to be compared
 
package/product1/product1.jar
package/product2/product2.jar
  points to and gives the first and second JAR's names, referencing them by their package paths
 
If the correct JAR names and paths were supplied, JarMaster outputs a list of differences between the JARs. This list consists of file names, each name accompanied by one or two "X" markers (in two columns) to the left.

For each file, if an X is found in the left column, this means the file in question is found only in the first JAR. If an X is found in the right column, the file is found only in the second JAR. Finally, if an X is found in both columns, this indicates that the file's name exists in both JARs, but there was a difference in file size and/or modification date.