uk.ac.starlink.util

## Class SuperJar

- java.lang.Object
- - uk.ac.starlink.util.SuperJar

-     public class SuperJar
      extends java.lang.Object

  Utility to generate a single jar file containing all the resources referenced by a given jar file. As well as the contents of the named jar file itself, the contents of any jar files referenced in the Class-Path line of that file's Manifest will be included, and so on recursively. This can be used to produce a standalone jar file for applications which do not require JNI components.

  This class has a `main` method, and is designed to be invoked from the command line.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SuperJar(java.io.File[] jarFiles, java.io.File[] flatFiles, java.lang.String[] jarExcludes, java.lang.String[] entryExcludes)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `main(java.lang.String[] args)` Writes a new jar or zip file based on the contents of an existing jar file and the jar files referenced by its manifest.
    `void` | `writeSingleJar(java.io.OutputStream out)` Writes the data from this object to a single jar file combining the contents of all the dependencies.
    `void` | `writeZipOfJars(java.io.OutputStream out)` Writes the data from this object to a zip file containing all the top-level and dependency jars as individual jar files in the same directory.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SuperJar

          public SuperJar(java.io.File[] jarFiles,
                          java.io.File[] flatFiles,
                          java.lang.String[] jarExcludes,
                          java.lang.String[] entryExcludes)
                   throws java.io.IOException

      Constructor.

      The `entryExcludes` values are full pathnames with no leading "/", interpreted as follows:

      - ending in "/": exclude that directory and all children
      - ending in "/*": exclude all flat files, but not subdirectories of that directory
      - otherwise: exclude the flat file with that exact name
      Parameters:
        `jarFiles` - top-level jar files containing files and dependencies
        `flatFiles` - files for inclusion at top level of output
        `jarExcludes` - names of jar files which may be named as class-path dependencies but which should not be included in the result
        `entryExcludes` - jar file entries which should be excluded from the result
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### writeSingleJar

          public void writeSingleJar(java.io.OutputStream out)
                              throws java.io.IOException

      Writes the data from this object to a single jar file combining the contents of all the dependencies.
      Parameters:
        `out` - destination stream
      Throws:
        `java.io.IOException`

    - #### writeZipOfJars

          public void writeZipOfJars(java.io.OutputStream out)
                              throws java.io.IOException

      Writes the data from this object to a zip file containing all the top-level and dependency jars as individual jar files in the same directory.
      Parameters:
        `out` - destination stream
      Throws:
        `java.io.IOException`

    - #### main

          public static void main(java.lang.String[] args)
                           throws java.io.IOException

      Writes a new jar or zip file based on the contents of an existing jar file and the jar files referenced by its manifest.

      ### Usage:

              SuperJar [-oj outjar] [-oz outzip]
                       [[-xjar jar] -xjar jar ...]
                       [[-xentry entry] -xentry entry ...]
                       jarfile [jarfile ...]

      If the `-oj` flag is given, it supplies the name of a monolithic jar file to output. `-o` is a deprecated synonym for `-oj`.

      If the `-oz` flag is given, it supplies the name of a zip file to output. This zip file will contain all the named and referenced jar files in a single flat directory.

      The `-xjar` * flag may be supplied one or more times to define jarfiles which should not be included, even if they are referenced in the manifest's Class-Path entry of a jar file which is included. The `exclude` argument thus defined is the name, optionally with one or more prepended path elements of the jar file to be excluded (e.g. axis.jar or axis/axis.jar would both work). `-x` is a deprecated synonym for `-xjar`.

      The `-xent` flag may be supplied one or more times to give full paths for jar entries which should not be included in the output. These are interpreted as follows:

      - ending in "/": exclude that directory and all children
      - ending in "/*": exclude all flat files, but not subdirectories of that directory
      - otherwise: exclude the flat file with that exact name

      The `jarfile` argument(s) will be combined to form the output file, all their contents and those of the jar files referenced in their Class-Path manifest entries will be used. The manifest of the first one will be used as the manifest of the output file (though its Class-Path entry will be empty). Zip files can be used as well, they work the same but have no manifest.

      Any `flat-file` arguments will be included as files at the top level of the output jar or zip file.

      Parameters:
        `args` - an array of command-line arguments as described above
      Throws:
        `java.io.IOException`