All Packages Class Hierarchy This Package Previous Next Index
Class utilities.JarMaker
java.lang.Object
|
+----utilities.JarMaker
- public class JarMaker
- extends Object
The JarMaker class is used to generate a smaller (and therefore
faster loading) JAR or ZIP file from a larger one,
based on the user's requirements.
In addition, JarMaker can also be used to:
- extract desired files from a JAR or ZIP file; or
- split a JAR or ZIP file into smaller JAR or ZIP files.
A JarMaker object can be included in the user's program,
or JarMaker can be run as a command line program, as follows:
java utilities.JarMaker [ options ]
Options
-source
sourceJarFile
-
Specifies the source JAR or ZIP file from which to derive the
destination JAR or ZIP file.
If a relative path is specified, the path is assumed to be relative to
the current directory.
If this option is specified as the first positional argument,
the tag (
-source
) is optional.
The -source option may be abbreviated to -s.
-destination
destinationJarFile
-
Specifies the destination JAR or ZIP file, which will contain the desired subset
of the files in the source JAR or ZIP file.
If a pathname is not specified, the file is created in the current directory.
The -destination option may be abbreviated to -d.
The default name is generated by appending
"Small"
to the
source file name. For example, if the source file is myfile.jar
,
then the default destination file would be myfileSmall.jar
.
-requiredFile
jarEntry1[,jarEntry2[...] ]
-
The files in the source JAR or ZIP file that are to be copied to the destination.
Entries are separated by commas (no spaces).
The specified files, along with all of their dependencies,
will be considered required.
Files are specified in JAR entry name syntax, such as
com/ibm/as400/access/DataQueue.class
.
The -requiredFile option may be abbreviated to -rf.
-additionalFile
file1[,file2[...] ]
-
Specifies additional files (not included in the source JAR or ZIP file)
which are to be copied to the destination.
Entries are separated by commas (no spaces).
Files are specified by either their
absolute path, or their path relative to the current directory.
The specified files will be included, regardless of the settings of
other options.
The -additionalFile option may be abbreviated to -af.
-additionalFilesDirectory
baseDirectory
-
Specifies the base directory for additional files.
This should be the parent directory of the
directory where the package path starts. For example, if file
foo.class
in package com.ibm.mypackage
is located in directory
C:\dir1\subdir2\com\ibm\mypackage\
, then specify base directory C:\dir1\subdir2
.
The -additionalFilesDirectory option may be abbreviated to -afd.
The default is the current directory.
-package
package1[,package2[...] ]
-
The packages that are required.
Entries are separated by commas (no spaces).
The -package option may be abbreviated to -p.
Package names are specified in standard syntax, such as
com.ibm.component
.
Note: The specified packages are simply included in the output.
No additional dependency analysis is done on the files in a package,
unless they are explicitly specified as required files.
-extract
[baseDirectory]
-
Extracts the desired entries of the source JAR or ZIP file
into the specified base directory, without generating a new JAR or ZIP file.
This option enables the user to build up a customized JAR or ZIP file
empirically, based on the requirements of their particular application.
When this option is specified,
-additionalFile
,
-additionalFilesDirectory
, and -destination
are ignored.
The -extract option may be abbreviated to -x.
By default, no extraction is done.
The default base directory is the current directory.
-split
[splitSize]
-
Splits the source JAR or ZIP file into smaller JAR or ZIP files.
No ZIP entries are added or excluded;
the entries in the source JAR or ZIP file are simply distributed
among the destination JAR or ZIP files.
The split size is in units of kilobytes (1024 bytes),
and specifies the maximum size for the destination files.
The destination files are created in the current directory,
and are named by appending integers to the source file name;
any existing files by the same name are overwritten.
For example, if the source JAR file is
myfile.jar
,
then the destination JAR files would be
myfile0.jar
, myfile1.jar
, and so on.
When this option is specified, all other options except
-source
and -verbose
are ignored.
The -split option may be abbreviated to -sp.
The default split size is 2 megabytes (2048 kilobytes).
-verbose
-
Causes progress messages to be displayed.
The -verbose option may be abbreviated to -v.
The default is non-verbose.
-help
-
Displays the help text.
The -help option may be abbreviated to -h.
The default is non-verbose.
At least one of the following options must be specified:
- -requiredFile
- -additionalFile
- -package
- -extract
- -split
If the following options are specified multiple times in a single command
string, only the final specification applies:
- -source
- -destination
- -additionalFilesDirectory
- -extract
- -split
Other options have a cumulative effect when specified multiple times
in a single command string.
Example usage
Suppose the source JAR file is named myJar.jar
,
and is in the current directory.
To create a JAR file that contains only the classes
mypackage.MyClass1
and
mypackage.MyClass2
, along with their dependencies,
do the following:
import utilities.JarMaker;
// Set up the list of required files.
Vector classList = new Vector ();
classList.addElement ("mypackage/MyClass1.class");
classList.addElement ("mypackage/MyClass2.class");
JarMaker jm = new JarMaker ();
jm.setRequiredFiles (classList);
// Make a new JAR file, that contains only MyClass1, MyClass2,
// and their dependencies.
File sourceJar = new File ("myJar.jar");
File newJar = jm.makeJar (sourceJar); // smaller JAR file
Alternatively, the above action can be performed directly
from the command line as follows:
java utilities.JarMaker -source myJar.jar
-requiredFile mypackage/MyClass1.class,mypackage/MyClass2.class
-
JarMaker()
- Constructs a JarMaker object.
-
addJarMakerListener(JarMakerListener)
- Adds a listener to the listener list.
-
extract(File)
- Extracts the desired entries and their dependencies from
the specified JAR or ZIP file.
-
extract(File, File)
- Extracts the desired entries and their dependencies from
the specified JAR or ZIP file.
-
getAdditionalFiles()
- Returns the additional files that are to be included in
the destination JAR or ZIP file.
-
getPackages()
- Returns the names of the packages that are to be included in the output.
-
getRequiredFiles()
- Returns the names of the required files specified by the user.
-
main(String[])
- Performs the actions specified in the invocation arguments.
-
makeJar(File)
- Generates a smaller JAR or ZIP file, containing only the desired entries
and their dependencies.
-
makeJar(File, File)
- Generates a smaller JAR or ZIP file, containing only the desired entries
and their dependencies.
-
removeJarMakerListener(JarMakerListener)
- Removes a listener from the listener list.
-
reset()
- Resets the JarMaker object to a clean, default state,
to facilitate object reuse.
-
setAdditionalFiles(Vector)
- Specifies additional files to include in the destination JAR or ZIP file.
-
setAdditionalFiles(Vector, File)
- Specifies additional files to include in the destination JAR or ZIP file.
-
setPackages(Vector)
- Specifies the names of packages that are to be included in the output.
-
setRequiredFiles(Vector)
- Specifies the names of required JAR or ZIP entries.
-
setVerbose()
- Sets
verbose
mode 'on'.
-
setVerbose(boolean)
- Sets
verbose
mode on or off.
-
split(File)
- Splits the specified JAR or ZIP file into smaller JAR or ZIP files
whose size does not exceed 2 megabytes.
-
split(File, int)
- Splits the specified source JAR or ZIP file into smaller JAR or ZIP files
whose size does not exceed the specified number of kilobytes.
JarMaker
public JarMaker()
- Constructs a JarMaker object.
addJarMakerListener
public synchronized void addJarMakerListener(JarMakerListener listener)
- Adds a listener to the listener list.
- Parameters:
- listener - The listener.
extract
public File extract(File sourceJarFile) throws FileNotFoundException, IOException, ZipException
- Extracts the desired entries and their dependencies from
the specified JAR or ZIP file.
The extracted files are placed under the current directory.
Note: No "additional files" are copied.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- Returns:
- The base directory under which the extracted files were written.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing the extracted files.
- Throws: ZipException
- If a ZIP error occurs when reading the source file.
extract
public void extract(File sourceJarFile,
File outputDirectory) throws FileNotFoundException, IOException, ZipException
- Extracts the desired entries and their dependencies from
the specified JAR or ZIP file.
Note: No "additional files" are copied.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- outputDirectory - The directory under which to put the extracted files.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing the extracted files.
- Throws: ZipException
- If a ZIP error occurs when reading the source file.
getAdditionalFiles
public Vector getAdditionalFiles()
- Returns the additional files that are to be included in
the destination JAR or ZIP file.
- Returns:
- The additional files specified by the user.
The list will be empty if none has been specified.
The list will contain only
java.io.File
objects.
getRequiredFiles
public Vector getRequiredFiles()
- Returns the names of the required files specified by the user.
- Returns:
- The names of required files specified by the user.
The list will be empty if none has been specified.
The list will contain only
String
objects.
getPackages
public Vector getPackages()
- Returns the names of the packages that are to be included in the output.
- Returns:
- The names of the required packages specified by the user.
The list will be empty if none has been specified.
The list will contain only
String
objects.
makeJar
public File makeJar(File sourceJarFile) throws FileNotFoundException, IOException, ZipException
- Generates a smaller JAR or ZIP file, containing only the desired entries
and their dependencies.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- Returns:
- The destination JAR or ZIP file.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing the destination file.
- Throws: ZipException
- If a ZIP error occurs when reading the source file
or writing the destination file.
makeJar
public void makeJar(File sourceJarFile,
File destinationJarFile) throws FileNotFoundException, IOException, ZipException
- Generates a smaller JAR or ZIP file, containing only the desired entries
and their dependencies.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- destinationJarFile - The destination JAR or ZIP file.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing the destination file.
- Throws: ZipException
- If a ZIP error occurs when reading the source file
or writing the destination file.
removeJarMakerListener
public synchronized void removeJarMakerListener(JarMakerListener listener)
- Removes a listener from the listener list.
- Parameters:
- listener - The listener.
reset
public void reset()
- Resets the JarMaker object to a clean, default state,
to facilitate object reuse.
setAdditionalFiles
public void setAdditionalFiles(Vector fileList)
- Specifies additional files to include in the destination JAR or ZIP file.
These are files that reside outside of the source JAR or ZIP file.
If an additional file resolves to the same entry name as an existing
entry in the source file, the additional file will replace the
existing entry in the generated JAR or ZIP file.
When deriving ZIP entry names,
the base directory for the files is the current directory.
Note: This augments any previously specified additional files.
This method does not verify the existence of the specified files.
- Parameters:
- fileList - The additional files to include in the
destination JAR or ZIP file.
The list should contain only
java.io.File
objects.
setAdditionalFiles
public void setAdditionalFiles(Vector fileList,
File baseDirectory)
- Specifies additional files to include in the destination JAR or ZIP file.
These are files that reside outside of the source JAR or ZIP file.
If an additional file resolves to the same entry name as an existing
entry in the source file, the additional file will replace the
existing entry in the generated JAR or ZIP file.
Note: This augments any previously specified additional files.
This method does not verify the existence of the specified files or directory.
- Parameters:
- fileList - The additional files to include in the
destination JAR or ZIP file.
The list should contain only
java.io.File
objects.
- baseDirectory - The base directory for the specifed files. This path
is used when assigning a ZIP entry name for the additional file.
The path below this directory
should match the package name sequence for the files.
For example, if the additional file is
C:\dir1\subdir2\com\ibm\myproduct\MyClass.class
,
and class MyClass
is in package com.ibm.myproduct
,
then the base directory should be set to C:\dir1\subdir2
.
setRequiredFiles
public void setRequiredFiles(Vector entryList)
- Specifies the names of required JAR or ZIP entries.
The names are specified in JAR entry name syntax, such as
com/ibm/component/className.class
.
Note: This augments any previously specified required entries.
This method does not verify the existence of the specified entries
in the source JAR or ZIP file.
- Parameters:
- entryList - The names of required JAR or ZIP entries.
The list should contain only
String
objects.
setPackages
public void setPackages(Vector packages)
- Specifies the names of packages that are to be included in the output.
Packages are specified in standard syntax, such as
com.ibm.component
.
The specified packages are simply included in the output.
No additional dependency analysis is done on the files in a package,
unless those files are also specified as required files.
Note: This augments any previously specified packages.
This method does not verify the existence of the specified packages
in the source JAR or ZIP file.
- Parameters:
- packages - The required packages.
The list should contain only
String
objects.
setVerbose
public void setVerbose()
- Sets
verbose
mode 'on'.
setVerbose
public void setVerbose(boolean verbose)
- Sets
verbose
mode on or off.
- Parameters:
- verbose - If
true
, turn verbose mode on;
otherwise turn verbose mode off.
split
public Vector split(File sourceJarFile) throws FileNotFoundException, IOException, ZipException
- Splits the specified JAR or ZIP file into smaller JAR or ZIP files
whose size does not exceed 2 megabytes.
No files are added or excluded; the entries in the source file
are simply distributed among the generated JAR or ZIP files.
If any single file within the source JAR or ZIP file exceeds
2 megabytes, a warning is printed to
System.err
.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- Returns:
- The generated files.
This is a list of
java.io.File
objects.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing a generated file.
- Throws: ZipException
- If a ZIP error occurs when reading the source file
or writing a generated file.
split
public Vector split(File sourceJarFile,
int splitSizeKbytes) throws FileNotFoundException, IOException, ZipException
- Splits the specified source JAR or ZIP file into smaller JAR or ZIP files
whose size does not exceed the specified number of kilobytes.
No files are added or excluded; the entries in the source file
are simply distributed among the destination files.
If any single file within the source file exceeds
the specified size, a warning is printed to
System.err
.
- Parameters:
- sourceJarFile - The source JAR or ZIP file.
- splitSizeKbytes - The maximum size for the generated JAR or ZIP files
(in kilobytes). Must be greater than zero.
- Returns:
- The generated files.
This is a list of
java.io.File
objects.
- Throws: FileNotFoundException
- If the source file does not exist.
- Throws: IOException
- If an I/O error occurs when reading the source file
or writing a generated file.
- Throws: ZipException
- If a ZIP error occurs when reading the source file
or writing a generated file.
main
public static void main(String args[])
- Performs the actions specified in the invocation arguments.
- Parameters:
- args - The command line arguments.
All Packages Class Hierarchy This Package Previous Next Index