uk.ac.starlink.util
Class SuperJar

java.lang.Object
  extended by uk.ac.starlink.util.SuperJar

public class SuperJar
extends 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
SuperJar(File[] jarFiles, File[] flatFiles, String[] jarExcludes, String[] entryExcludes)
          Constructor.
 
Method Summary
static void main(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(OutputStream out)
          Writes the data from this object to a single jar file combining the contents of all the dependencies.
 void writeZipOfJars(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(File[] jarFiles,
                File[] flatFiles,
                String[] jarExcludes,
                String[] entryExcludes)
         throws IOException
Constructor.

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:
IOException
Method Detail

writeSingleJar

public void writeSingleJar(OutputStream out)
                    throws IOException
Writes the data from this object to a single jar file combining the contents of all the dependencies.

Parameters:
out - destination stream
Throws:
IOException

writeZipOfJars

public void writeZipOfJars(OutputStream out)
                    throws 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:
IOException

main

public static void main(String[] args)
                 throws 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 define jar entry names (names of directories or files within the included jar archives) which should not be included. Directory names should include a trailing "/".

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:
IOException

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.