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.
net.jini.config.Configuration 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.
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
org.apache.river.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 | Method and Description |
---|---|
static void |
main(String[] args)
Generates a wrapper JAR file for the specified JAR files.
|
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[]) . |
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 net.jini.loader.pref.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
org.apache.river.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
Copyright © 2016–2018. All rights reserved.