The main benefit of using
JClass JarMaster to create JARs from the command prompt is that you can include
it in your build scripts. You can call the JarMaster command in your scripts
in the same way you would use the JDK's jar
command. However,
with JarMaster you can take advantage of its functiontality and create a
streamlined JAR.
Please see Creating a JAR from the Command Prompt for information
about this procedure.
JClass JarMaster includes
a class called JarMasterAntTask
which allows users to easily incorporate JarMaster
into a build system that uses Apache Ant. JarMasterAntTask
extends org.apache.tools.ant.Task
,
and thus can be used in the same way as any normal Ant task.
Note:In order to use JarMaster as an Ant task, one must be using Apache Ant 1.5 or later and have jcjarmaster.jar on their classpath when running Ant.
The following example builds a JAR named MyJar.jar, which includes all the classes in the current directory, their direct dependencies, and the indirect dependencies as specified in the manifest file (manifest.txt):
<!-- ##################################################################### -->
<!------------------------------ JClass JarMaster Ant Task Example ------------------------------------------>
<!-- ##################################################################### -->
<project name="jarmaster" default="jar">
<!-- JarMaster Ant Task Definition -->
<taskdef resource="com/klg/jclass/jarmaster/taskdef.properties" />
<!-- Building MyJar.jar -->
<target name="jar" description="Build jar">
<jarmaster manifest="manifest.txt"
clearDefaults="yes"
compressionLevel="9"
output="MyJar.jar">
<!-- Classpath settings follow the standard Ant classpath rules -->
<classpath>
<pathelement path="."/>
</classpath>
<!-- Excluded packages can be either class names or package names -->
<excludepackage name="org/apache/batik"/>
<excludepackage name="org/apache/tools/ant"/>
<excludepackage name="java"/>
<excludepackage name="javax"/>
<excludepackage name="sun"/>
<!-- Files to include in the JAR are specified using a standard Ant fileset -->
<fileset dir="." >
<include name="*.class"/>
</fileset>
</jarmaster>
</target>
</project>
<taskdef name="jarmaster" classname="com/klg/jclass/jarmaster/JarMasterAntTask" />
Property |
Ant Type |
Description |
excludepackage |
PatternSet |
A list of packages and classes to exclude from the
JAR. |
classpath |
Path |
The path to use to search for dependencies. By
default, the current system classpath is used -- accessed via System.getProperty("java.class.path") . |
manifest |
File |
The manifest file to use. |
clearDefaults |
boolean |
If true , clears the default list of packages to exclude
from the JAR. |
isJar |
boolean |
If true , creates a JAR; otherwise, creates a zip file. |
compressionLevel |
int |
The level of compression for the JAR. An integer
between 0 (no compression) and 9 (max compression). |
output |
File |
The name of the output JAR. |
mainClass |
String |
The name of the class in the JAR to use as a main
class (for executable JARs). |
fileSets |
Vector of FileSet objects |
The list of files to add to the JAR. Both the files and
their dependencies must be accessible throught the classpath. |