Deprecated

This task has been deprecated. Use a zipfileset or zipgroupfileset with the Jar task or Zip task instead. For a task based on the JDK's jlink tool, see Link.

Description

For a task based on the JDK's jlink tool, see Link. This task is for something else entirely.

Links entries from sub-builds and libraries.

The jlink task can be used to build jar and zip files, similar to the jar task. However, jlink provides options for controlling the way entries from input files are added to the output file. Specifically, capabilities for merging entries from multiple zip or jar files is available.

If a mergefile is specified directly (eg. at the top level of a mergefiles pathelement) and the mergefile ends in .zip or .jar, entries in the mergefile will be merged into the outfile. A file with any other extension will be added to the output file, even if it is specified in the mergefiles element. Directories specified in either the mergefiles or addfiles element are added to the output file as you would expect: all files in subdirectories are recursively added to the output file with appropriate prefixes in the output file (without merging).

In the case where duplicate entries and/or files are found among the files to be merged or added, jlink merges or adds the first entry and ignores all subsequent entries.

jlink ignores META-INF directories in mergefiles. Users should supply their own manifest information for the output file.

It is possible to refine the set of files that are being jlinked. This can be done with the includes, includesfile, excludes, excludesfile, and defaultexcludes attributes on the addfiles and mergefiles nested elements. With the includes or includesfile attribute you specify the files you want to have included by using patterns. The exclude or excludesfile attribute is used to specify the files you want to have excluded. This is also done with patterns. And finally with the defaultexcludes attribute, you can specify whether you want to use default exclusions or not. See the section on directory based tasks, on how the inclusion/exclusion of files works, and how to write patterns. The patterns are relative to the base directory.

Parameters

Attribute Description Required
outfile the path of the output file. Yes
compress whether or not the output should be compressed. true, yes, or on result in compressed output. No; defaults to uncompressed (inflated) output
mergefiles files to be merged into the output, if possible. Exactly one of the two
addfiles files to be added to the output.

Examples

The following will merge the entries in mergefoo.jar and mergebar.jar into out.jar. mac.jar and pc.jar will be added as single entries to out.jar.

<jlink compress="false" outfile="out.jar">
   <mergefiles>
     <pathelement path="${build.dir}/mergefoo.jar"/>
     <pathelement path="${build.dir}/mergebar.jar"/>
   </mergefiles>
   <addfiles>
     <pathelement path="${build.dir}/mac.jar"/>
     <pathelement path="${build.dir}/pc.zip"/>
   </addfiles>
</jlink>

Non-deprecated alternative to the above:

<jar compress="false" destfile="out.jar">
  <zipgroupfileset dir="${build.dir}">
    <include name="mergefoo.jar"/>
    <include name="mergebar.jar"/>
  </zipgroupfileset>
  <fileset dir="${build.dir}">
    <include name="mac.jar"/>
    <include name="pc.jar"/>
  </fileset>
</jar>

Suppose the file foo.jar contains two entries: bar.class and barnone/myClass.zip. Suppose the path for file foo.jar is build/tempbuild/foo.jar. The following example will provide the entry tempbuild/foo.jar in the out.jar.

<jlink compress="false" outfile="out.jar">
   <mergefiles>
     <pathelement path="build/tempbuild"/>
   </mergefiles>
</jlink>

However, the next example would result in two top-level entries in out.jar, namely bar.class and barnone/myClass.zip

<jlink compress="false" outfile="out.jar">
   <mergefiles>
     <pathelement path="build/tempbuild/foo.jar"/>
   </mergefiles>
</jlink>