Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.modules

public Class Link

extends Task
Class Inheritance
Imports
java.io.File, .PrintStream, .ByteArrayOutputStream, .Reader, .IOException, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .FileVisitResult, .SimpleFileVisitor, java.nio.file.attribute.BasicFileAttributes, java.util.Collection, .List, .ArrayList, .Map, .LinkedHashMap, .Properties, .Collections, .Objects, java.util.spi.ToolProvider, java.util.stream.Stream, .Collectors, org.apache.tools.ant.BuildException, .Project, .Task, org.apache.tools.ant.types.EnumeratedAttribute, .LogLevel, .Path, .Reference, .ResourceCollection, org.apache.tools.ant.util.CompositeMapper, .MergingMapper, .FileUtils, .ResourceUtils

Assembles jmod files into an executable image. Equivalent to the JDK jlink command.

Supported attributes:

destDir
Root directory of created image. (required)
modulePath
Path of modules. Should be a list of .jmod files. Required, unless nested module path or modulepathref is present.
modulePathRef
Reference to path of modules. Referenced path should be a list of .jmod files.
modules
Comma-separated list of modules to assemble. Required, unless one or more nested <module> elements are present.
observableModules
Comma-separated list of explicit modules that comprise "universe" visible to tool while linking.
launchers
Comma-separated list of commands, each of the form name=module or name=module/mainclass
excludeFiles
Comma-separated list of patterns specifying files to exclude from linked image. Each is either a standard PathMatcher pattern or @filename.
excludeResources
Comma-separated list of patterns specifying resources to exclude from jmods. Each is either a standard PathMatcher pattern or @filename.
locales
Comma-separated list of extra locales to include, requires jdk.localedata module
resourceOrder
Comma-separated list of patterns specifying resource search order. Each is either a standard PathMatcher pattern or @filename.
bindServices
boolean, whether to link service providers; default is false
ignoreSigning
boolean, whether to allow signed jar files; default is false
includeHeaders
boolean, whether to include header files; default is true
includeManPages
boolean, whether to include man pages; default is true
includeNativeCommands
boolean, whether to include native executables normally generated for image; default is true
debug
boolean, whether to include debug information; default is true
verboseLevel
If set, jlink will produce verbose output, which will be logged at the specified Ant log level (DEBUG, VERBOSE, INFO}, WARN, or ERR).
compress
compression level, one of:
0
none
no compression (default)
1
strings
constant string sharing
2
zip
zip compression
endianness
Must be little or big, default is native endianness
checkDuplicateLegal
Boolean. When merging legal notices from different modules because they have the same name, verify that their contents are identical. Default is false, which means any license files with the same name are assumed to have the same content, and no checking is done.
vmType
Hotspot VM in image, one of:
  • client
  • server
  • minimal
  • all (default)

Supported nested elements

<modulepath>
path element
<module>
May be specified multiple times. Only attribute is required name attribute.
<observableModule>
May be specified multiple times. Only attribute is required name attribute.
<launcher>
May be specified multiple times. Attributes:
  • name (required)
  • module (required)
  • mainClass (optional)
<locale>
May be specified multiple times. Only attribute is required name attribute.
<resourceOrder>
Explicit resource search order in image. May be specified multiple times. Exactly one of these attributes must be specified:
pattern
A standard PathMatcher pattern
listFile
Text file containing list of resource names (not patterns), one per line
If the resourceOrder attribute is also present on the task, its patterns are treated as if they occur before patterns in nested <resourceOrder> elements.
<excludeFiles>
Excludes files from linked image tree. May be specified multiple times. Exactly one of these attributes is required:
pattern
A standard PathMatcher pattern
listFile
Text file containing list of file names (not patterns), one per line
<excludeResources>
Excludes resources from jmods. May be specified multiple times. Exactly one of these attributes is required:
pattern
A standard PathMatcher pattern
listFile
Text file containing list of resource names (not patterns), one per line
<compress>
Must have level attribute, whose permitted values are the same as the compress task attribute described above. May also have a files attribute, which is a comma-separated list of patterns, and/or nested <files> elements, each with either a pattern attribute or listFile attribute.
<releaseInfo>
Replaces, augments, or trims the image's release info properties. This may specify any of the following:
  • A file attribute, pointing to a Java properties file containing new release info properties that will entirely replace the current ones.
  • A delete attribute, containing comma-separated property keys to remove from application's release info, and/or any number of nested <delete> elements, each with a required key attribute.
  • One or more nested <add> elements, containing either key and value attributes, or a file attribute and an optional charset attribute.
Since
1.10.6
See Also
jlink tool reference

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
Link.Compression

Child element fully describing compression of a linked image.

public static class
Link.CompressionLevel

Possible attribute values for compression level of a linked image:

0
none
no compression (default)
1
strings
constant string sharing
2
zip
zip compression
public static class
Link.Endianness

Possible values for linked image endianness: little and big.

public class
Link.Launcher

Child element representing a custom launcher command in a linked image.

public class
Link.LocaleSpec

Child element that contains a pattern matching Java locales.

public class
Link.ModuleSpec

Child element that explicitly names a Java module.

public class
Link.PatternListEntry

Child element type which specifies a jlink files pattern.

public class
Link.ReleaseInfo

Child element describing changes to the default release properties of a linked image.

public class
Link.ReleaseInfoEntry

Grandchild element describing additional release info properties for a linked image.

public class
Link.ReleaseInfoKey

Grandchild element representing deletable key in a linked image's release properties.

public static class
Link.VMType

Possible values for JVM type in linked image: client, server, minimal, or all.

Field Summary

Modifier and TypeField and Description
private boolean
bindServices

Whether to include all service provides in linked image which are present in the module path and which are needed by modules explicitly linked.

private boolean
checkDuplicateLegal

Whether to check duplicate legal notices from different modules actually have identical content, not just indentical names, before merging them.

private Link.Compression
compression

Describes which files in image to compress, and how to compress them.

private Link.CompressionLevel
compressionLevel

Simple compression level applied to linked image.

private boolean
debug

Whether to include classes' debug information or strip it.

private Link.Endianness
endianness

Endianness of some files (?) in linked image.

private final List<Link.PatternListEntry>
excludedFiles

Files to exclude from linked image.

private final List<Link.PatternListEntry>
excludedResources

Resources in linked modules which should be excluded from linked image.

private boolean
ignoreSigning

Whether to ignore signed jars (and jmods based on signed jars) when linking, instead of emitting an error.

private boolean
includeHeaders

Whether to include header files from linked modules in image.

private boolean
includeManPages

Whether to include man pages from linked modules in image.

private boolean
includeNativeCommands

Whether to include native commands from linked modules in image.

private static final String
INVALID_LAUNCHER_STRING

Error message for improperly formatted launcher attribute.

private final List<Link.Launcher>
launchers

Additional runnable programs which linker will place in image's bin directory.

private final List<Link.LocaleSpec>
locales

Locales to explicitly include from jdk.localdata module.

private Path
modulePath

Path of directories containing linkable modules.

private final List<Link.ModuleSpec>
modules

Modules to include in linked image.

private final List<Link.ModuleSpec>
observableModules

If non-empty, list of all modules linker is permitted to know about.

private final List<Link.PatternListEntry>
ordering

Resource ordering.

private File
outputDir

Directory into which linked image will be placed.

private final List<Link.ReleaseInfo>
releaseInfo

Changes to linked image's default release info.

private LogLevel
verboseLevel

The Ant logging level at which verbose output of linked should be emitted.

private Link.VMType
vmType

Type of VM in linked image.

Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
private Collection<String>

Returns:

new list of jlink arguments
buildJlinkArgs
()

Creates list of arguments to jlink tool, based on this instance's current state.

public Link.Compression

Returns:

new, unconfigured child element
createCompress
()

Creates child <compress> element that specifies the level of compression the linker will apply, and optionally, which files in the image will be compressed.

public Link.PatternListEntry

Returns:

new, unconfigured child element
createExcludeFiles
()

Creates child <excludeFiles> element that specifies files to exclude from linked modules when assembling linked image.

public Link.PatternListEntry

Returns:

new, unconfigured child element
createExcludeResources
()

Creates child <excludeResources> element that specifies resources in linked modules that will be excluded from linked image.

public Link.Launcher

Returns:

new, unconfigured child element
createLauncher
()

Creates child <launcher> element that can contain information on additional executable in the linked image.

public Link.LocaleSpec

Returns:

new, unconfigured child element
createLocale
()

Creates child <locale> element that specifies a Java locale, or set of locales, to include from the jdk.localedata module in the linked image.

public Link.ModuleSpec

Returns:

new, unconfigured child element
createModule
()

Adds child <module> element, specifying a module to link.

public Path

Returns:

new, empty child element
createModulePath
()

Adds child <modulePath> element.

public Link.ModuleSpec

Returns:

new, unconfigured child element
createObservableModule
()

Creates child <observableModule> element that represents one of the modules the linker is permitted to know about.

public Link.ReleaseInfo

Returns:

new, unconfigured child element
createReleaseInfo
()

Creates child <releaseInfo> element that modifies the default release properties of the linked image.

public Link.PatternListEntry

Returns:

new, unconfigured child element
createResourceOrder
()

Creates child <resourceOrder element that specifies explicit ordering of resources in linked image.

private void
deleteTree(Path
root of tree to delete
dir
)

Recursively deletes a file tree.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Invokes the jlink tool to create a new linked image, unless the output directory exists and all of its files are files are newer than all files in the module path.
public boolean

Returns:

true if linked will pull in service provides, false if not
getBindServices
()

Attribute indicating whether linked image should pull in providers in the module path of services used by explicitly linked modules.

public boolean

Returns:

true if legal notice files with same name should be checked for identical content, false to suppress check
getCheckDuplicateLegal
()

Attribute indicating whether linker should check legal notices with duplicate names, and refuse to merge them (usually using symbolic links) if their respective content is not identical.

public Link.CompressionLevel

Returns:

compression level to apply, or null for none
getCompress
()

Attribute indicating level of compression linker will apply to image.

public boolean

Returns:

true if debug information will be retained, false if it will be stripped
getDebug
()

Attribute indicating whether linker should keep or strip debug information in classes.

public File

Returns:

directory where linked image will reside
getDestDir
()

Required attribute containing directory where linked image will be created.

public Link.Endianness

Returns:

endianness to apply, or null to platform default
getEndianness
()

Attribute which indicates whether certain files in the linked image will be big-endian or little-endian.

public boolean

Returns:

true if signed jars are allowed, false if modules based on signed jars cause an error
getIgnoreSigning
()

Attribute indicating whether linker should allow modules made from signed jars.

public boolean

Returns:

true if header files should be included, false to exclude them
getIncludeHeaders
()

Attribute indicating whether to include header files from linked modules in image.

public boolean

Returns:

true if man pages should be included, false to exclude them
getIncludeManPages
()

Attribute indicating whether to include man pages from linked modules in image.

public boolean

Returns:

true if native commands should be included, false to exclude them
getIncludeNativeCommands
()

Attribute indicating whether to include generated native commands, and native commands from linked modules, in image.

public Path

Returns:

current module path, possibly null
getModulePath
()

Attribute containing path of directories containing linkable modules.

public LogLevel

Returns:

logging level at which to show linker's verbose output, or null to disable verbose output
getVerboseLevel
()

Attribute indicating whether linker should produce verbose output, and at what logging level that output should be shown.

public Link.VMType

Returns:

type of JVM linked image will have
getVmType
()

Attribute indicating what type of JVM the linked image should have.

public void
setBindServices(final boolean
whether to include service providers
bind
)

Sets attribute indicating whether linked image should pull in providers in the module path of services used by explicitly linked modules.

public void
setCheckDuplicateLegal(final boolean
true if legal notice files with same name should be checked for identical content, false to suppress check
check
)

Sets attribute indicating whether linker should check legal notices with duplicate names, and refuse to merge them (usually using symbolic links) if their respective content is not identical.

public void
setCompress(final Link.CompressionLevel
compression level to apply, or null for none
level
)

Sets attribute indicating level of compression linker will apply to image.

public void
setDebug(final boolean
true if debug information should be retained, false if it should be stripped
debug
)

Sets attribute indicating whether linker should keep or strip debug information in classes.

public void
setDestDir(final File
directory in which image will be created by linker
dir
)

Sets attribute indicating directory where linked image will be created.

public void
setEndianness(final Link.Endianness
endianness to apply, or null to use platform default
endianness
)

Sets attribute which indicates whether certain files in the linked image will be big-endian or little-endian.

public void
setExcludeFiles(String
comman-separated list of patterns
patternList
)

Sets attribute containing a list of patterns denoting files to exclude from linked modules when assembling linked image.

public void
setExcludeResources(String
comma-separated list of patterns
patternList
)

Sets attribute containing a list of patterns denoting resources to exclude from linked modules in linked image.

public void
setIgnoreSigning(final boolean
true to have linker allow signed jars, false to have linker emit an error for signed jars
ignore
)

Sets attribute indicating whether linker should allow modules made from signed jars.

public void
setIncludeHeaders(final boolean
true if header files should be included, false to exclude them
include
)

Sets attribute indicating whether to include header files from linked modules in image.

public void
setIncludeManPages(final boolean
true if man pages should be included, false to exclude them
include
)

Sets attribute indicating whether to include man pages from linked modules in image.

public void
setIncludeNativeCommands(final boolean
true if native commands should be included, false to exclude them
include
)

Sets attribute indicating whether to include generated native commands, and native commands from linked modules, in image.

public void
setLaunchers(final String
comma-separated list of launcher data
launcherList
)

Sets attribute containing comma-separated list of information needed for additional executables in the linked image.

public void
setLocales(final String
comma-separated list of locale patterns
localeList
)

Sets attribute containing a list of locale patterns, to specify Java locales to include from jdk.localedata module in linked image.

public void
setModulePath(final Path
new module path
path
)

Sets attribute containing path of directories containing linkable modules.

public void
setModulePathRef(final Reference
path reference
ref
)

Sets module path as a reference.

public void
setModules(final String
comma-separated list of module names
moduleList
)

Sets attribute containing list of modules to link.

public void
setObservableModules(final String
comma-separated list of module names
moduleList
)

Sets attribute containing modules linker is permitted to know about.

public void
setResourceOrder(final String
comma-separated list of patterns
patternList
)

Sets attribute containing a list of patterns that explicitly order resources in the linked image.

public void
setVerboseLevel(final LogLevel
level logging level at which to show linker's verbose output, or null to disable verbose output
level
)

Sets attribute indicating whether linker should produce verbose output, and at what logging level that output should be shown.

public void
setVmType(final Link.VMType
type of JVM linked image will have
type
)

Set attribute indicating what type of JVM the linked image should have.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType