public class JarWrapper extends Object
Class-Path
manifest attribute listing a group of JAR files to
be loaded from a common codebase. It may also, depending on applicability
and selected options, contain a JAR index file, a preferred class list
and/or a Main-Class
manifest entry for the grouped JAR files.
The following items are discussed below:
The JarWrapper
tool is applicable in the following deployment
situations, which may overlap:
JarWrapper
can be used to produce a wrapper
JAR file with a combined preferred list. Preferred resources are
described in the documentation for the net.jini.loader.pref
package.
JarWrapper
can be used to produce a wrapper
JAR file with a Class-Path
attribute that uses HTTPMD
URLs. HTTPMD URLs are described in the documentation for the
net.jini.url.httpmd
package.
Configuration
) which are not
present in the JAR file or its Class-Path
,
JarWrapper
can be used to produce a wrapper JAR file
which includes the extra classes in its Class-Path
while
retaining the original Main-Class
declaration; the
wrapper JAR file can then be executed in place of the original JAR
file.
Using the Tool
JarWrapper
can be run directly from the
command line or can be invoked programmatically using the
wrap
method.
To run the tool on UNIX platforms:
To run the tool on Microsoft Windows platforms:java -jar install_dir/lib/jarwrapper.jar processing_options
java -jar install_dir\lib\jarwrapper.jar processing_options
A more specific example with options for running directly from a Unix command line might be:
where install_dir is the directory where the Apache River release is installed. This command line would result in the creation of a wrapper JAR file,% java -jar install_dir/lib/jarwrapper.jar \ -httpmd=SHA-1 wrapper.jar base_dir src1.jar src2.jar
wrapper.jar
, in the current working
directory, whose contents would be based on the source JAR files
src1.jar
and src2.jar
(as well as any other JAR
files referenced transitively through their Class-Path
attributes or JAR indexes). The paths for src1.jar
and
src2.jar
, as well as any transitively referenced JAR files,
would be resolved relative to the base_dir
directory. The
Class-Path
attribute of wrapper.jar
would use
HTTPMD URLs with SHA-1 digests. If any of the HTTPMD URLs encountered is
found to be invalid and can not be resolved, the JarWrapper
operation will fail.
The equivalent programmatic invocation of JarWrapper
would be:
JarWrapper.wrap("wrapper.jar", "base_dir", new String[]{ "src1.jar", "src2.jar" }, "SHA-1", true, "manifest.mf" );
JarWrapper
uses the Logger
named
com.sun.jini.tool.JarWrapper
to log information at the
following logging levels:
Level | Description |
---|---|
WARNING
| Generated JAR index entries that do not end in ".jar"
|
FINE
| Names of processed source JAR files and output wrapper JAR file |
FINER
| Processing of Main-Class and Class-Path
attributes, and presence of preferred lists and JAR indexes
|
FINEST
| Processing and compilation of preferred lists and JAR indexes |
Modifier and Type | Class and Description |
---|---|
private static class |
JarWrapper.JarIndexReader
Parses JAR indexes.
|
private static class |
JarWrapper.JarIndexWriter
Assembles and writes JAR indexes.
|
private static class |
JarWrapper.LocalizedIllegalArgumentException
IllegalArgumentException with a localized detail message.
|
private static class |
JarWrapper.LocalizedIOException
IOException with a localized detail message.
|
private static class |
JarWrapper.PreferredListReader
Parses preferred lists.
|
private static class |
JarWrapper.PreferredListWriter
Compiles and writes combined preferred lists.
|
private static class |
JarWrapper.SourceJarURL
Represents URL to a source JAR file.
|
Modifier and Type | Field and Description |
---|---|
private File |
baseDir
Base directory,
null in case the JAR files are specified as
absolute files, the so called flatten classpath option. |
private StringBuffer |
classPath |
private static String |
DEFAULT_HTTPMD_ALGORITHM |
private File |
destJar |
private MessageDigest |
digest |
private JarWrapper.JarIndexWriter |
indexWriter |
private static Logger |
logger |
private String |
mainClass |
private Manifest |
manifest |
private JarWrapper.PreferredListWriter |
prefWriter |
private static ResourceBundle |
resources |
private static Object |
resourcesLock |
private Set |
seenJars |
private JarWrapper.SourceJarURL[] |
srcJars |
Modifier | Constructor and Description |
---|---|
private |
JarWrapper(String destJar,
String baseDir,
String[] srcJars,
String httpmdAlg,
boolean index,
Manifest mf,
List apiClasses)
Initializes JarWrapper based on the given values.
|
Modifier and Type | Method and Description |
---|---|
private void |
deleteWrapperJar()
Attempts to delete wrapper JAR file.
|
private List |
getClassPath(JarFile jar)
Returns URLs contained in the Class-Path attribute (if any) of the given
JAR file, as a list of SourceJarURL instances.
|
private static String |
getDigestString(MessageDigest digest,
File file)
Returns a string representation of the message digest of the given file.
|
private static String |
getMainClass(JarFile jar)
Returns the value of the Main-Class attribute of the given JAR file, or
null if none is present.
|
private static String |
getResourceString(String key)
Returns localized format string, obtained from the resource bundle for
JarWrapper, that corresponds to the given key, or null if the resource
bundle does not contain a corresponding string.
|
(package private) static String |
localize(String key)
Returns localized message text corresponding to the given key string.
|
(package private) static String |
localize(String key,
Object val)
Returns localized message text corresponding to the given key string,
passing the provided value as an argument when formatting the message.
|
(package private) static String |
localize(String key,
Object[] vals)
Returns localized message text corresponding to the given key string,
passing the provided values as an argument when formatting the message.
|
static void |
main(String[] args)
Generates a wrapper JAR file for the specified JAR files.
|
private void |
outputWrapperJar()
Writes wrapper JAR file based on information from processed source JARs.
|
private void |
process(JarWrapper.SourceJarURL url,
JarWrapper.PreferredListReader prefReader)
Processes source JAR file indicated by the given URL, determining
preferred resources using the provided preferred list reader.
|
private static Manifest |
retrieveManifest(String fileName)
Returns the Manifest object derived from a manifest file as specified
on the command line.
|
private static void |
setLoggingLevel(Level level)
Sets logging and console handler output level.
|
private void |
wrap()
Processes source JAR files and outputs wrapper JAR file.
|
static void |
wrap(String destJar,
String[] srcJars,
String httpmdAlg,
boolean index,
Manifest mf,
List apiClasses)
Generates a wrapper JAR file based on the provided values in the same
manner as described in the documentation for
main(java.lang.String[]) . |
static void |
wrap(String destJar,
String baseDir,
String[] srcJars,
String httpmdAlg,
boolean index)
Invokes
wrap with the provided values and a null manifest. |
static void |
wrap(String destJar,
String baseDir,
String[] srcJars,
String httpmdAlg,
boolean index,
Manifest mf)
Generates a wrapper JAR file based on the provided values in the same
manner as described in the documentation for
main(java.lang.String[]) . |
static void |
wrap(String destJar,
String baseDir,
String[] srcJars,
String httpmdAlg,
boolean index,
Manifest mf,
List apiClasses)
Generates a wrapper JAR file based on the provided values in the same
manner as described in the documentation for
main(java.lang.String[]) . |
private static ResourceBundle resources
private static final Object resourcesLock
private static final Logger logger
private final File destJar
private final File baseDir
null
in case the JAR files are specified as
absolute files, the so called flatten classpath option.private final JarWrapper.SourceJarURL[] srcJars
private final Manifest manifest
private final MessageDigest digest
private final JarWrapper.JarIndexWriter indexWriter
private final JarWrapper.PreferredListWriter prefWriter
private final StringBuffer classPath
private String mainClass
private final Set seenJars
private static final String DEFAULT_HTTPMD_ALGORITHM
public static void main(String[] args)
[ options ] dest-jar base-dir src-jar [ src-jar ...]The dest-jar argument specifies the name of the wrapper JAR file to generate. The base-dir argument specifies the base directory from which to locate source JAR files to wrap. The src-jar arguments are non-absolute URLs to "top-level" source JAR files relative to base-dir; they also constitute the basis of the
Class-Path
attribute included in the generated
wrapper JAR file. JAR files not present in the command line but
indirectly referenced via JAR index or Class-Path
entries
in source JAR files will themselves be used as source JAR files, and
will appear alongside the top-level source JAR files in the
Class-Path
attribute of the wrapper JAR file in depth-first
order, with JAR index references appearing before
Class-Path
references. This utility does not modify any
source JAR files.
If any of the top-level source JAR files contain preferred resources (as
indicated by a preferred list in the JAR file), then a preferred list
describing resource preferences across all source JAR files will be
included in the wrapper JAR file. The preferred list of a top-level
source JAR file is interpreted as applying to that JAR file along with
all JAR files transitively referenced by it through JAR index or
Class-Path
entries, excluding JAR files that have already
been encountered in the processing of preceding top-level JAR files. If
a given top-level source JAR file does not contain a preferred list,
then all resources contained in it and its transitively referenced JAR
files (again, excluding those previously encountered) are considered not
preferred. Preferred lists are described further in the documentation
for PreferredClassLoader
.
If any of the top-level source JAR files declare a
Main-Class
manifest entry, then the wrapper JAR file will
include a Main-Class
manifest entry whose value is that of
the first top-level source JAR file listed on the command line which
defines a Main-Class
entry.
Note that attribute values generated by this utility, such as those for
the Class-Path
and Main-Class
attributes
described above, do not take precedence over values for the same
attributes contained in a manifest file explicitly specified using the
-manifest
option (described below).
Supported options for this tool include:
-verbose
com.sun.jini.tool.JarWrapper
logger to Level.FINER
.
-httpmd[=algorithm]
Class-Path
attribute of the generated wrapper JAR file. The default is to
use HTTP URLs. Digests for HTTPMD URLs are calculated using the
given algorithm, or SHA-1 if none is specified.
-noindex
-manifest=file
m
flag. In the current
version there are four possible attributes that can be overridden
in the target Manifest. These are
Name.MANIFEST_VERSION
,
Name("Created-By")
, Name.CLASS_PATH
and
Name.MAIN_CLASS
. Any additonal attributes beyond
these four will be appended to the manifest attribute list and
will appear in the resultant MANIFEST.MF
file.
public static void wrap(String destJar, String baseDir, String[] srcJars, String httpmdAlg, boolean index) throws IOException
wrap
with the provided values and a null
manifest.destJar
- name of the wrapper JAR file to generatebaseDir
- base directory from which to locate source JAR
files to wrapsrcJars
- list of top-level source JAR files to processhttpmdAlg
- name of algorithm to use for generating HTTPMD URLs, or
null
if plain HTTP URLs should be usedindex
- if true
, generate a JAR index; if
false
, do not generate oneIOException
- if an I/O error occurs while processing source JAR
files or generating the wrapper JAR fileIllegalArgumentException
- if the provided values are invalidNullPointerException
- if destJar
,
baseDir
, srcJars
, or any element of
srcJars
is null
public static void wrap(String destJar, String baseDir, String[] srcJars, String httpmdAlg, boolean index, Manifest mf) throws IOException
main(java.lang.String[])
. The only
difference between this method and main
is that it receives
its values as explicit arguments instead of in a command line, and
indicates failure by throwing an exception.destJar
- name of the wrapper JAR file to generatebaseDir
- base directory from which to locate source JAR
files to wrapsrcJars
- list of top-level source JAR files to processhttpmdAlg
- name of algorithm to use for generating HTTPMD URLs, or
null
if plain HTTP URLs should be usedindex
- if true
, generate a JAR index; if
false
, do not generate onemf
- manifest containing values to include in the manifest file
of the generated wrapper JAR fileIOException
- if an I/O error occurs while processing source JAR
files or generating the wrapper JAR fileIllegalArgumentException
- if the provided values are invalidNullPointerException
- if destJar
,
baseDir
, srcJars
, or any element of
srcJars
is null
public static void wrap(String destJar, String baseDir, String[] srcJars, String httpmdAlg, boolean index, Manifest mf, List apiClasses) throws IOException
main(java.lang.String[])
. The only
difference between this method and main
is that it receives
its values as explicit arguments instead of in a command line, and
indicates failure by throwing an exception.destJar
- name of the wrapper JAR file to generatebaseDir
- base directory from which to locate source JAR
files to wrapsrcJars
- list of top-level source JAR files to processhttpmdAlg
- name of algorithm to use for generating HTTPMD URLs, or
null
if plain HTTP URLs should be usedindex
- if true
, generate a JAR index; if
false
, do not generate onemf
- manifest containing values to include in the manifest file
of the generated wrapper JAR fileapiClasses
- list of binary class names (type String
)
that must be considered API classes in case a preferences conflict
arises during wrapping of the JAR files, or null
in case
no such list is availableIOException
- if an I/O error occurs while processing source JAR
files or generating the wrapper JAR fileIllegalArgumentException
- if the provided values are invalidNullPointerException
- if destJar
,
baseDir
, srcJars
, or any element of
srcJars
is null
public static void wrap(String destJar, String[] srcJars, String httpmdAlg, boolean index, Manifest mf, List apiClasses) throws IOException
main(java.lang.String[])
.
The difference between this method and the 6 and 7-arg wrap
method is that the source JAR files must be specified by an absolute path
and that for processing the classpath will be flattened, i.e. each source
JAR file will be considered as relative to its parent directory (that
will serve as a virtual base directory) for the assembly of the
Class-Path
entry.
destJar
- name of the wrapper JAR file to generatesrcJars
- list of top-level source JAR files to process, must be
absolute pathshttpmdAlg
- name of algorithm to use for generating HTTPMD URLs, or
null
if plain HTTP URLs should be usedindex
- if true
, generate a JAR index; if
false
, do not generate onemf
- manifest containing values to include in the manifest file
of the generated wrapper JAR fileapiClasses
- list of binary class names (type String
)
that must be considered API classes in case a preferences conflict
arises during wrapping of the JAR files, or null
in case
no such list is availableIOException
- if an I/O error occurs while processing source JAR
files or generating the wrapper JAR fileIllegalArgumentException
- if the provided values are invalidNullPointerException
- if destJar
,
srcJars
, or any element of srcJars
is
null
private void wrap() throws IOException
IOException
private void process(JarWrapper.SourceJarURL url, JarWrapper.PreferredListReader prefReader) throws IOException
IOException
private List getClassPath(JarFile jar) throws IOException
IOException
private void outputWrapperJar() throws IOException
IOException
private void deleteWrapperJar()
private static String getMainClass(JarFile jar) throws IOException
IOException
private static String getDigestString(MessageDigest digest, File file) throws IOException
IOException
private static void setLoggingLevel(Level level)
static String localize(String key)
static String localize(String key, Object val)
static String localize(String key, Object[] vals)
private static String getResourceString(String key)
private static Manifest retrieveManifest(String fileName) throws IOException
IOException
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.