utilities

Class JarMaker

  • java.lang.Object
    • utilities.JarMaker
  • Direct Known Subclasses:
    ToolboxJarMaker

    Deprecated. 
    Use the Java 9 module tools instead.

    public class JarMaker
    extends java.lang.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.
    -fileRequired 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 -fileRequired option may be abbreviated to -f.
    -fileExcluded jarEntry1[,jarEntry2[...] ]
    The files in the source JAR or ZIP file that are to be excluded from the destination, and from dependency analysis. Entries are separated by commas (no spaces). Files are specified in JAR entry name syntax, such as com/ibm/as400/access/DataQueue.class. The -fileExcluded option may be abbreviated to -fx.
    -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.
    -packageExcluded package1[,package2[...] ]
    The packages that are to be excluded. Entries are separated by commas (no spaces). The -packageExcluded option may be abbreviated to -px. Package names are specified in standard syntax, such as com.ibm.component.
    -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 removed; 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 no help text.

    At least one of the following options must be specified:

    • -fileRequired
    • -fileExcluded
    • -additionalFile
    • -package
    • -packageExcluded
    • -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.setFilesRequired (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
            -fileRequired mypackage/MyClass1.class,mypackage/MyClass2.class
    
    • Constructor Summary

      Constructors 
      Constructor and Description
      JarMaker()
      Deprecated. 
      Constructs a JarMaker object.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void addJarMakerListener(JarMakerListener listener)
      Deprecated. 
      Adds a listener to the listener list.
      java.io.File extract(java.io.File sourceJarFile)
      Deprecated. 
      Extracts the desired entries and their dependencies from the specified JAR or ZIP file.
      void extract(java.io.File sourceJarFile, java.io.File outputDirectory)
      Deprecated. 
      Extracts the desired entries and their dependencies from the specified JAR or ZIP file.
      java.util.Vector getAdditionalFiles()
      Deprecated. 
      Returns the additional files that are to be included in the destination JAR or ZIP file.
      java.util.Vector getFilesExcluded()
      Deprecated. 
      Returns the names of the required files specified by the user.
      java.util.Vector getFilesRequired()
      Deprecated. 
      Returns the names of the required files specified by the user.
      java.util.Vector getPackages()
      Deprecated. 
      Returns the names of the packages that are to be included in the output.
      java.util.Vector getPackagesExcluded()
      Deprecated. 
      Returns the names of the packages that are to be excluded from the output.
      java.util.Vector getRequiredFiles()
      Deprecated. 
      Use getFilesRequired() instead.
      static void main(java.lang.String[] args)
      Deprecated. 
      Performs the actions specified in the invocation arguments.
      java.io.File makeJar(java.io.File sourceJarFile)
      Deprecated. 
      Generates a smaller JAR or ZIP file, containing only the desired entries and their dependencies.
      void makeJar(java.io.File sourceJarFile, java.io.File destinationJarFile)
      Deprecated. 
      Generates a smaller JAR or ZIP file, containing only the desired entries and their dependencies.
      void removeJarMakerListener(JarMakerListener listener)
      Deprecated. 
      Removes a listener from the listener list.
      void reset()
      Deprecated. 
      Resets the JarMaker object to a clean, default state, to facilitate object reuse.
      void setAdditionalFiles(java.util.Vector fileList)
      Deprecated. 
      Specifies additional files to include in the destination JAR or ZIP file.
      void setAdditionalFiles(java.util.Vector fileList, java.io.File baseDirectory)
      Deprecated. 
      Specifies additional files to include in the destination JAR or ZIP file.
      void setFilesExcluded(java.util.Vector entryList)
      Deprecated. 
      Specifies the names of entries in the source JAR or ZIP file that are to be excluded from the target.
      void setFilesRequired(java.util.Vector entryList)
      Deprecated. 
      Specifies the names of required entries in the source JAR or ZIP file.
      void setPackages(java.util.Vector packages)
      Deprecated. 
      Specifies the names of packages that are to be included in the output.
      void setPackagesExcluded(java.util.Vector packages)
      Deprecated. 
      Specifies the names of packages that are to be excluded from the output.
      void setRequiredFiles(java.util.Vector entryList)
      Deprecated. 
      Use setFilesRequired() instead.
      void setVerbose()
      Deprecated. 
      Sets verbose mode 'on'.
      void setVerbose(boolean verbose)
      Deprecated. 
      Sets verbose mode on or off.
      java.util.Vector split(java.io.File sourceJarFile)
      Deprecated. 
      Splits the specified JAR or ZIP file into smaller JAR or ZIP files whose size does not exceed 2 megabytes.
      java.util.Vector split(java.io.File sourceJarFile, int splitSizeKbytes)
      Deprecated. 
      Splits the specified source JAR or ZIP file into smaller JAR or ZIP files whose size does not exceed the specified number of kilobytes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JarMaker

        public JarMaker()
        Deprecated. 
        Constructs a JarMaker object.
    • Method Detail

      • addJarMakerListener

        public void addJarMakerListener(JarMakerListener listener)
        Deprecated. 
        Adds a listener to the listener list.
        Parameters:
        listener - The listener.
      • extract

        public java.io.File extract(java.io.File sourceJarFile)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException,
                                    java.util.zip.ZipException
        Deprecated. 
        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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing the extracted files.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file.
      • extract

        public void extract(java.io.File sourceJarFile,
                   java.io.File outputDirectory)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            java.util.zip.ZipException
        Deprecated. 
        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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing the extracted files.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file.
      • getAdditionalFiles

        public java.util.Vector getAdditionalFiles()
        Deprecated. 
        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 java.util.Vector getRequiredFiles()
        Deprecated. Use getFilesRequired() instead.
        Returns:
        Vector
      • getFilesRequired

        public java.util.Vector getFilesRequired()
        Deprecated. 
        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.
      • getFilesExcluded

        public java.util.Vector getFilesExcluded()
        Deprecated. 
        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 java.util.Vector getPackages()
        Deprecated. 
        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.
      • getPackagesExcluded

        public java.util.Vector getPackagesExcluded()
        Deprecated. 
        Returns the names of the packages that are to be excluded from the output.
        Returns:
        The names of the excluded packages specified by the user. The list will be empty if none has been specified. The list will contain only String objects.
      • makeJar

        public java.io.File makeJar(java.io.File sourceJarFile)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException,
                                    java.util.zip.ZipException
        Deprecated. 
        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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing the destination file.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file or writing the destination file.
      • makeJar

        public void makeJar(java.io.File sourceJarFile,
                   java.io.File destinationJarFile)
                     throws java.io.FileNotFoundException,
                            java.io.IOException,
                            java.util.zip.ZipException
        Deprecated. 
        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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing the destination file.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file or writing the destination file.
      • removeJarMakerListener

        public void removeJarMakerListener(JarMakerListener listener)
        Deprecated. 
        Removes a listener from the listener list.
        Parameters:
        listener - The listener.
      • reset

        public void reset()
        Deprecated. 
        Resets the JarMaker object to a clean, default state, to facilitate object reuse.
      • setAdditionalFiles

        public void setAdditionalFiles(java.util.Vector fileList)
        Deprecated. 
        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(java.util.Vector fileList,
                              java.io.File baseDirectory)
        Deprecated. 
        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.
      • setPackages

        public void setPackages(java.util.Vector packages)
        Deprecated. 
        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.
      • setPackagesExcluded

        public void setPackagesExcluded(java.util.Vector packages)
        Deprecated. 
        Specifies the names of packages that are to be excluded from the output. Packages are specified in standard syntax, such as com.ibm.component.
        Note: This augments any previously specified packages.
        Parameters:
        packages - The packages to be excluded. The list should contain only String objects.
      • setRequiredFiles

        public void setRequiredFiles(java.util.Vector entryList)
        Deprecated. Use setFilesRequired() instead.
        Parameters:
        entryList -
      • setFilesRequired

        public void setFilesRequired(java.util.Vector entryList)
        Deprecated. 
        Specifies the names of required entries in the source JAR or ZIP file. 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 file.
        Parameters:
        entryList - The names of required JAR or ZIP entries. The list should contain only String objects.
      • setFilesExcluded

        public void setFilesExcluded(java.util.Vector entryList)
        Deprecated. 
        Specifies the names of entries in the source JAR or ZIP file that are to be excluded from the target. The names are specified in JAR entry name syntax, such as com/ibm/component/className.class.
        Note: This augments any previously specified excluded entries. This method does not verify the existence of the specified entries in the source file.
        Parameters:
        entryList - The names of JAR or ZIP entries to be excluded. The list should contain only String objects.
      • setVerbose

        public void setVerbose()
        Deprecated. 
        Sets verbose mode 'on'.
      • setVerbose

        public void setVerbose(boolean verbose)
        Deprecated. 
        Sets verbose mode on or off.
        Parameters:
        verbose - If true, turn verbose mode on; otherwise turn verbose mode off.
      • split

        public java.util.Vector split(java.io.File sourceJarFile)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException,
                                      java.util.zip.ZipException
        Deprecated. 
        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 removed; 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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing a generated file.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file or writing a generated file.
      • split

        public java.util.Vector split(java.io.File sourceJarFile,
                             int splitSizeKbytes)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException,
                                      java.util.zip.ZipException
        Deprecated. 
        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 removed; 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:
        java.io.FileNotFoundException - If the source file does not exist.
        java.io.IOException - If an I/O error occurs when reading the source file or writing a generated file.
        java.util.zip.ZipException - If a ZIP error occurs when reading the source file or writing a generated file.
      • main

        public static void main(java.lang.String[] args)
        Deprecated. 
        Performs the actions specified in the invocation arguments.
        Parameters:
        args - The command line arguments.