Build a Jar archive.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.jdk.jar |
Category: | Archiving tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory GeneratorTaskFactory ProcessTaskFactory |
Produces: | EFile (the target). |
See also: | WarTF EarTF At4JUnzipTF |
Description:
Build a new Jar archive.
There are two ways that a META-INF/MANIFEST.MF
file can be added to the
created Jar file. It can be set using the manifest
property, or it can be copied to the Jar file from the sources. A
manifest set using the manifest property always has
precedence.
Required properties
Properties
comment | top |
The Jar file comment.
- Setter method:
setComment(String s)
Set the comment.parameters:s
– The comment.- Default value:
- Created by Schmant -- www.schmant.org
entryInfoProvider | top |
A provider for extra Zip entry information for each entry (file or directory) in the archive.
- Setter method:
setExtraInfoProvider(ZipEntryInfoProvider p)
Set the providerparameters:p
– The provider.
level | top |
The compression level for entries added to the archive. The level is represented as an integer between 0 (no compression) and 9 (best compression).
- Setter method:
setLevel(int l)
Set the compression levelparameters:l
– The level (0-9).- Default value:
- The default compression level of the Zlib library. Currently 6, but that may change in the future.
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
manifest | top |
The archive file's META-INF/MANIFEST.MF
file
- Setter method:
setManifest(Object o)
parameters:- Setter method:
setManifest(Manifest m)
parameters:m
– A manifest- Default value:
- See
org/schmant/task/jdk/jar/default_manifest.txt
in Schmant's source distribution
method | top |
The compression method for entities added to the archive.
- Setter method:
setMethod(ZipCompressionMethod m)
Set the compression method represented by aparameters:ZipCompressionMethod
enum.m
– AZipCompressionMethod
representing the compression method. This is one of- DEFLATED
- FILTERED
- HUFFMAN_ONLY
- NO_COMPRESSION
- Setter method:
setMethod(int i)
Set the compression method represented by one of theparameters:Deflater
constants.- Default value:
- DEFLATED
overwriteStrategy | top |
The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.
If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.
Non-empty directories are never overwritten, regardless of the chosen strategy.
- Setter method:
setOverwrite(boolean b)
Setting this to a value ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.b
– Should an existing entity be overwritten?- Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.parameters:strat
– The overwrite strategy.- Default value:
- DontOverwriteAndThrowException
- See also:
- target
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sources (required) | top |
A collection of files and directories that should be added to the Jar archive. The contents of source directories are added recursively.
There are two ways that EntityFilter:s can be used to limit which child entities of a Directory that is added:
- Using a DirectoryView as source: Only files and directories that match the view's filter will be added. The task will not proceed down into child directories that don't pass the filter.
- Using a DirectoryAndFilter as source: Only files and directories that match the filter will be added. The task will proceed down into all child directories. If an entity is added, but not its parent directory, the parent directory will be created automatically.
By default entities are added to the Jar file in the same location relative
to the Jar file root that they had relative to the source directory that they
were added from. For instance, the file d/d2/f
will be added at
the location /d2/f
in the Jar file if d
is used as
a source directory. If instead d2
is used as a source directory,
f
will be added at the location /f
.
To add entities at other locations in the tree, a source entity can be wrapped
in an EntityAndAbsoluteLocation object. For instance, if the
directory d
containing the file d/d2/f
is added with
a new EntityAndAbsoluteLocation(d,
new AbsoluteLocation("/foo")
, the file will have the
location /foo/d2/f
in the Jar file.
- Setter method:
addSource(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byAbstractJavaZipTask.createIterator()
.- Setter method:
addSources(Object o)
Add one or several sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byAbstractJavaZipTask.createIterator()
.- Setter method:
clearSources()
Discard all sources.- Setter method:
setSource(Object o)
Set one or several sources and discard previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byAbstractJavaZipTask.createIterator()
.- Setter method:
setSources(Object o)
Set one or several sources and discard previously set sources.parameters:o
– A source object or an array or collection of source objects.
Interpreted byAbstractJavaZipTask.createIterator()
.
target (required) | top |
The target Jar file.
- Setter method:
setTarget(Object o)
parameters:- See also:
- overwriteStrategy
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
Examples
Example 1
Create a Jar archive from the class files in the directory
hierarchy under d1
. The archive will be put in directory
d
.
JavaScript
Example 2
Create a Jar archive from the class files in the directory
hierarchy under d1
, using the manifest file
/tmp/my_manifest.txt
. The archive will be put in directory
d
.
JavaScript
Example 3
Create a Jar archive from the class files in the directory
hierarchy under d1
. Use a manually created manifest.
The archive will be put in directory d
.
Groovy
JavaScript
JRuby
Jython
Example 4
Create a Jar archive from the files in the directory hierarchy under
d1
. Add an entry to the META-INF/services
catalog (the
example is from the Jar file specification). Put the Jar file in the directory
d
.
JavaScript
Example 5
Create a new Jar file, tutti.jar
, containing
the data from this.jar
, that.jar
and
everything_else.jar
.
Groovy
JavaScript
JRuby
Jython
* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.