tentackle-jlink:jlink

Full name:

org.tentackle:tentackle-jlink-maven-plugin:25.20.1.0:jlink

Description:

Creates a self-contained java application with the jlink tool.

This mojo works for modular, non-modular and even mixed applications. It's not just a wrapper for jlink, but analyzes the project's dependencies and finds the best strategy to invoke jlink to create a directory containing an application-specific jimage module. As a result, it requires only minimum configuration.

Basically, applications fall into one of 3 categories:

  1. Full-blown modular applications: all module-infos must require real modules only. Jlink creates an image from those modules. Optional artifacts and runtime modules can still be added.
  2. Modular applications with non-modular dependencies: jlink is used to create an image from the minimum necessary java runtime modules only, which are determined by the plugin either from the module-infos or via the jdeps tool. The application's dependencies are placed on the modulepath via the generated run-script.
  3. Non-modular traditional classpath applications: same as 2, but all dependencies are placed on the classpath.
Since it is very likely, that even modern modular applications require some 3rd-party dependencies not modularized yet, most of those applications will probably fall into the second category.

Artifacts not processed by jlink are copied to separate folders and passed to the java runtime explicitly via the module- and/or classpath. A platform-specific launch script will be generated according to the runTemplate. For applications using Tentackle's auto update feature, an update script is generated via the updateTemplate as well. Finally, the created directory is packed into a deployable zip file.

The minimum plugin configuration is very simple:

  ...
  <packaging>jlink</packaging>
  ...
      <plugin>
        <groupId>org.tentackle</groupId>
        <artifactId>tentackle-jlink-maven-plugin</artifactId>
        <version>${tentackle.version}</version>
        <extensions>true</extensions>
        <configuration>
          <mainModule>com.example</mainModule>
          <mainClass>com.example.MyApp</mainClass>
        </configuration>
      </plugin>
The freemarker templates are copied to the project's template folder, if missing. They become part of the project and can be changed easily according to project specific needs (for example by adding runtime arguments). To install and edit the templates before running jlink (or jpackage, see JPackageMojo ), use InitMojo first.

The template model provides the following variables:

  • mainModule: the name of the main module. Empty if classpath application.
  • mainClass: the name of the main class.
  • modulePath: the module path.
  • classPath: the class path.
  • phase: the mojo lifecycle phase.
  • goal: the plugin goal (jlink or jpackage).
  • id: the execution id.
  • layered: whether isolated module layers are configured (see getLayers()). Only if layered: bootstrapModule and bootstrapClass, the module and class to launch instead of the main class, and layersConfigPath, the path of the generated layers configuration.
  • runScript: the name of the generated run script (update template only).
  • all system properties (dots in property names translated to camelCase, e.g. "os.name" becomes "osName").
  • all maven properties (translated to camelCase as well).
  • the plugin configuration getVariables().
The order in which the properties and variables override each other is configured via getVariablesPrecedence() . The other variables cannot be overridden.

Modules not passed to jlink and automatic modules are copied to the mp folder and added to the modulePath template variable. If no such modules are detected, no folder is created.
Non-modular classpath artifacts are copied to the cp folder and added to the classPath template variable. Again, the folder will only be created if necessary.
Additional project resources, such as property files or logger configurations, are copied to the conf directory and this directory prepended to the classpath.

The generation of the ZIP-file and attachment of the artifact for installation and deployment can be customized by an application-specific implementation. This allows further modification of the generated image or files in the jlink target directory. It is also possible to add more than one artifact, for example, each with a different configuration. To do so, provide a plugin dependency that contains a class annotated with @Service(ArtifactCreator).

Notice that you can create an image for a different java version than the one used for the maven build process by selecting a toolchain via <jdkToolchain> (see org.tentackle.maven.AbstractTentackleMojo.getToolchain()).

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: runtime.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: package.

Required Parameters

Name Type Since Description
<imageDirectory> File - The directory created by jlink holding the image.
Default: ${project.build.directory}/jlink
<mainClass> String - The name of the main class.
<variablesPrecedence> String - Defines the precedence of properties and variables.
By default, system properties are overridden by maven properties which are overridden by the extra template variables.

The case-insensitive keywords are:

  • system, sys: for system properties
  • maven, mvn, properties, props, pom: maven properties
  • variables, vars, var, extras, extra, template: extra template variables

Default: system, maven, variables

Optional Parameters

Name Type Since Description
<addModules> List<String> - Extra jre or jdk modules to add to the image.
Useful to add the runtime localization module or extra tools in the bin-directory.

Example:

<addModules>
  <addModule>jdk.localedata</addModule>
  <addModule>jdk.jcmd</addModule>
</addModules>
<charset> String - The encoding to read and write files.
Applied JVM-wide, see org.tentackle.maven.AbstractTentackleMojo.determineEncoding() .
Default: ${project.build.sourceEncoding}
<classpathDependencies> List<ClasspathDependency> - Dependencies that should go to the classpath instead of the module-path.
<compress> String - Compression of resources.
Corresponds to the jlink option --compress, i.e. zip-0 to zip-9 (the legacy values 0, 1 and 2 are deprecated since Java 21).
<excludeModules> List<String> - Modules to exclude.
Necessary only if a dependency refers to removed api even if not used at all at runtime.
<excludeModules>
  <excludeModule>jdk8internals</excludeModule>
</excludeModules>
<excludeResources> List<String> - Resources to exclude from the image.
Corresponds to the jlink option --exclude-resources. Each entry is a pattern as accepted by jlink, i.e. a glob (the default) or regex:.

Defaults to DEFAULT_EXCLUDE_RESOURCES. If configured, the list replaces the default. Blank entries are ignored, so a single empty <excludeResource/> excludes nothing.

Example:

  <excludeResources>
    <excludeResource>**/OSGI-INF/**</excludeResource>
    <excludeResource>*.jcov</excludeResource>
  </excludeResources>
<extraClassifier> String - Additional classifier to add to deployed artifacts.
<extraClasspathElements> List<String> - Extra classpath elements.
Pathnames are relative to the image root.
<extraDirectories> List<File> - Extra directories to copy to the image.
<failOnAutomaticRequired> Boolean - Controls the behavior if an automatic module is required.
  • default: log such modules as warnings
  • true: log as an error and let the build fail
  • false: log as info
This flag is ignored, if a classpath application is built, i.e., no mainModule is given.
<ignoreSigningInformation> boolean - Suppresses a fatal error when signed modular JARs are linked in the runtime image.
Corresponds to the jlink option --ignore-signing-information
Default: false
<jdepsTool> File - Explicit path to the jdeps tool.
Only if toolchains cannot be used.
See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain()
User Property: jdepsTool
<jdkToolchain> Map<String,String> - Toolchain for invocation of external tools.
Explicitly specifies the "jdk" toolchain for this plugin only. Overrides the toolchain selected by the maven-toolchain-plugin, if any.

Example:

  <jdkToolchain>
    <version>25</version>
  </jdkToolchain>
To deselect the toolchain configured by the maven-toolchain-plugin:
  <jdkToolchain></jdkToolchain>
<jlinkOptions> List<String> - Extra jlink options.
Provided for platform-specific or hidden options, such as --upgrade-files.
<jlinkTool> File - Explicit path to the jlink tool.
Only if toolchains cannot be used.
See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain()
User Property: jlinkTool
<layers> List<Layer> - Named, isolated ModuleLayers for dependencies that must run isolated from each other - typically because two of them need different, otherwise conflicting versions of the same module.

If empty (the default), the application is built exactly as without this feature at all: a single, unlayered boot ModuleLayer. If not empty, mainClass is launched by org.tentackle.common.LayerBootstrap instead of directly, which builds the configured ModuleLayer graph at startup and then hands off to the real main class. See the layers.md documentation.


See also: leafLayer
<leafLayer> String - The name of the layer holding the application's own mainModule , used as the leaf entry of the generated layers.properties. Required if layers is not empty, and must not collide with any of their names.
<mainModule> String - The name of the module holding the main class.
If missing, the plugin will build an application running on the classpath.
<minLogLevel> String - The minimum logging java.util.logging.Level to redirect java.util logging to the maven logger.
Any name or value accepted by java.util.logging.Level.parse(java.lang.String) .
Default: WARNING
<modulePathOnly> List<String> - List of full-blown modules that should be moved to the module path explicitly.
By default, all full-blown modules are passed to the jlink tool. If a module is listed for the module path only, the module will be moved to the mp folder instead.
This may become necessary if a 3rd-party full-blown module (illegally!) requires automatic modules, which would cause all artifacts to be moved to the module path by this plugin automatically, since the jlink tool can only handle full-blown modules.

Please notice that this workaround is only available for non-required modules, i.e., modules that "plug in" via the ServiceFinder or some other dependency injection mechanism.

The main module of a layered application (see layers) is always module-path-only, without being listed here.

If all modules must be moved to the mp folder, the single values true, all or * can be used as a shortcut.

Examples:

   <modulePathOnly>
       <!-- kwik 0.10.9 illegally requires automatic module io.whitfin:siphash -->
       <module>org.tentackle.quic</module>
       <module>tech.kwik.core</module>
   </modulePathOnly>
or
  <modulePathOnly>all</modulePathOnly>
<nameTemplate> String - The name of the template to generate the name of the runner script.
The default template yields run.cmd on Windows and run.sh on all other platforms.
Default: name.ftl
<noHeaderFiles> boolean - Suppress the include directory.
Corresponds to the jlink option --no-header-files.
Default: false
<noManPages> boolean - Suppress the man directory.
Corresponds to the jlink option --no-man-pages
Default: false
<resourcesDirectory> File - The directory holding extra resources, such as logger configurations or database credentials, that will be copied to the conf directory.
Defaults to the maven-resources-plugin's destination directory, usually target/classes.
If no resources must be copied, for example, in server-images for production, set this to any non-existent directory, for example "none".
Default: ${project.build.directory}/classes
<runTemplate> String - The name of the runner script template.
Default: run.ftl
<saveOpts> File - The optional file holding the jlink options.
Corresponds to the jlink option --save-opts.
<skip> Boolean - Skips processing.
If not set, defaults to true if packaging is "pom" and the execution is recursive (see org.tentackle.maven.AbstractTentackleMojo.isSkippedByDefault() ).
<stripDebug> boolean - Strip debug information.
Corresponds to the jlink option --strip-debug.
Default: false
<templateDir> File - The directory holding the script templates.
Default: ${project.basedir}/templates
<updateTemplate> String - The name of the update script template.
Default: update.ftl
<variables> Map<String,Object> - Extra variables for template or artifact generation.

For example, the subproject's basedir:

 <variables>
   <project>${project.basedir}</project>
 </variables>
And then use it in package-image.ftl for file paths, such as:
  --icon ${project}/src/pkg/myapp.ico
<verbosity> String - The verbosity.
One of "default", "info" or "debug". Other values are treated as "default".
If not set, debug is turned on by Maven's global debug flag (see command line switch -X).
Default: ${tentackle.verbosity}
<withUpdater> boolean - Enables the auto-update feature.

For the jlink goal an extra update script will be generated via the JLinkMojo.getUpdateTemplate(). The update script will be named bin/update.<extension> where the extension is derived from the platform (cmd on Windows, otherwise sh for unixes).

For the jpackage goal an extra ZIP-file is created holding the jpackage image's files and an update script generated via getPackageUpdateTemplate().

For an implementation of the auto-update feature see the Tentackle modules tentackle-update and tentackle-fx-rdc-update. Whereas tentackle-update can be used by any kind of application, the frontend part tentackle-fx-rdc-update requires a Tentackle FX application.

<zipDirectory> File - The directory where to store the ZIP files.
Default: ${project.build.directory}

Parameter Details

<addModules>

Extra jre or jdk modules to add to the image.
Useful to add the runtime localization module or extra tools in the bin-directory.

Example:

<addModules>
  <addModule>jdk.localedata</addModule>
  <addModule>jdk.jcmd</addModule>
</addModules>
  • Type: java.util.List<java.lang.String>
  • Required: No

<charset>

The encoding to read and write files.
Applied JVM-wide, see org.tentackle.maven.AbstractTentackleMojo.determineEncoding() .
  • Type: java.lang.String
  • Required: No
  • Default: ${project.build.sourceEncoding}

<classpathDependencies>

Dependencies that should go to the classpath instead of the module-path.
  • Type: java.util.List<org.tentackle.maven.plugin.jlink.ClasspathDependency>
  • Required: No

<compress>

Compression of resources.
Corresponds to the jlink option --compress, i.e. zip-0 to zip-9 (the legacy values 0, 1 and 2 are deprecated since Java 21).
  • Type: java.lang.String
  • Required: No

<excludeModules>

Modules to exclude.
Necessary only if a dependency refers to removed api even if not used at all at runtime.
<excludeModules>
  <excludeModule>jdk8internals</excludeModule>
</excludeModules>
  • Type: java.util.List<java.lang.String>
  • Required: No

<excludeResources>

Resources to exclude from the image.
Corresponds to the jlink option --exclude-resources. Each entry is a pattern as accepted by jlink, i.e. a glob (the default) or regex:.

Defaults to DEFAULT_EXCLUDE_RESOURCES. If configured, the list replaces the default. Blank entries are ignored, so a single empty <excludeResource/> excludes nothing.

Example:

  <excludeResources>
    <excludeResource>**/OSGI-INF/**</excludeResource>
    <excludeResource>*.jcov</excludeResource>
  </excludeResources>
  • Type: java.util.List<java.lang.String>
  • Required: No

<extraClassifier>

Additional classifier to add to deployed artifacts.
  • Type: java.lang.String
  • Required: No

<extraClasspathElements>

Extra classpath elements.
Pathnames are relative to the image root.
  • Type: java.util.List<java.lang.String>
  • Required: No

<extraDirectories>

Extra directories to copy to the image.
  • Type: java.util.List<java.io.File>
  • Required: No

<failOnAutomaticRequired>

Controls the behavior if an automatic module is required.
  • default: log such modules as warnings
  • true: log as an error and let the build fail
  • false: log as info
This flag is ignored, if a classpath application is built, i.e., no mainModule is given.
  • Type: java.lang.Boolean
  • Required: No

<ignoreSigningInformation>

Suppresses a fatal error when signed modular JARs are linked in the runtime image.
Corresponds to the jlink option --ignore-signing-information
  • Type: boolean
  • Required: No
  • Default: false

<imageDirectory>

The directory created by jlink holding the image.
  • Type: java.io.File
  • Required: Yes
  • Default: ${project.build.directory}/jlink

<jdepsTool>

Explicit path to the jdeps tool.
Only if toolchains cannot be used.
See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain()
  • Type: java.io.File
  • Required: No
  • User Property: jdepsTool

<jdkToolchain>

Toolchain for invocation of external tools.
Explicitly specifies the "jdk" toolchain for this plugin only. Overrides the toolchain selected by the maven-toolchain-plugin, if any.

Example:

  <jdkToolchain>
    <version>25</version>
  </jdkToolchain>
To deselect the toolchain configured by the maven-toolchain-plugin:
  <jdkToolchain></jdkToolchain>
  • Type: java.util.Map<java.lang.String, java.lang.String>
  • Required: No

<jlinkOptions>

Extra jlink options.
Provided for platform-specific or hidden options, such as --upgrade-files.
  • Type: java.util.List<java.lang.String>
  • Required: No

<jlinkTool>

Explicit path to the jlink tool.
Only if toolchains cannot be used.
See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain()
  • Type: java.io.File
  • Required: No
  • User Property: jlinkTool

<layers>

Named, isolated ModuleLayers for dependencies that must run isolated from each other - typically because two of them need different, otherwise conflicting versions of the same module.

If empty (the default), the application is built exactly as without this feature at all: a single, unlayered boot ModuleLayer. If not empty, mainClass is launched by org.tentackle.common.LayerBootstrap instead of directly, which builds the configured ModuleLayer graph at startup and then hands off to the real main class. See the layers.md documentation.


See also: leafLayer
  • Type: java.util.List<org.tentackle.maven.plugin.jlink.Layer>
  • Required: No

<leafLayer>

The name of the layer holding the application's own mainModule , used as the leaf entry of the generated layers.properties. Required if layers is not empty, and must not collide with any of their names.
  • Type: java.lang.String
  • Required: No

<mainClass>

The name of the main class.
  • Type: java.lang.String
  • Required: Yes

<mainModule>

The name of the module holding the main class.
If missing, the plugin will build an application running on the classpath.
  • Type: java.lang.String
  • Required: No

<minLogLevel>

The minimum logging java.util.logging.Level to redirect java.util logging to the maven logger.
Any name or value accepted by java.util.logging.Level.parse(java.lang.String) .
  • Type: java.lang.String
  • Required: No
  • Default: WARNING

<modulePathOnly>

List of full-blown modules that should be moved to the module path explicitly.
By default, all full-blown modules are passed to the jlink tool. If a module is listed for the module path only, the module will be moved to the mp folder instead.
This may become necessary if a 3rd-party full-blown module (illegally!) requires automatic modules, which would cause all artifacts to be moved to the module path by this plugin automatically, since the jlink tool can only handle full-blown modules.

Please notice that this workaround is only available for non-required modules, i.e., modules that "plug in" via the ServiceFinder or some other dependency injection mechanism.

The main module of a layered application (see layers) is always module-path-only, without being listed here.

If all modules must be moved to the mp folder, the single values true, all or * can be used as a shortcut.

Examples:

   <modulePathOnly>
       <!-- kwik 0.10.9 illegally requires automatic module io.whitfin:siphash -->
       <module>org.tentackle.quic</module>
       <module>tech.kwik.core</module>
   </modulePathOnly>
or
  <modulePathOnly>all</modulePathOnly>
  • Type: java.util.List<java.lang.String>
  • Required: No

<nameTemplate>

The name of the template to generate the name of the runner script.
The default template yields run.cmd on Windows and run.sh on all other platforms.
  • Type: java.lang.String
  • Required: No
  • Default: name.ftl

<noHeaderFiles>

Suppress the include directory.
Corresponds to the jlink option --no-header-files.
  • Type: boolean
  • Required: No
  • Default: false

<noManPages>

Suppress the man directory.
Corresponds to the jlink option --no-man-pages
  • Type: boolean
  • Required: No
  • Default: false

<resourcesDirectory>

The directory holding extra resources, such as logger configurations or database credentials, that will be copied to the conf directory.
Defaults to the maven-resources-plugin's destination directory, usually target/classes.
If no resources must be copied, for example, in server-images for production, set this to any non-existent directory, for example "none".
  • Type: java.io.File
  • Required: No
  • Default: ${project.build.directory}/classes

<runTemplate>

The name of the runner script template.
  • Type: java.lang.String
  • Required: No
  • Default: run.ftl

<saveOpts>

The optional file holding the jlink options.
Corresponds to the jlink option --save-opts.
  • Type: java.io.File
  • Required: No

<skip>

Skips processing.
If not set, defaults to true if packaging is "pom" and the execution is recursive (see org.tentackle.maven.AbstractTentackleMojo.isSkippedByDefault() ).
  • Type: java.lang.Boolean
  • Required: No

<stripDebug>

Strip debug information.
Corresponds to the jlink option --strip-debug.
  • Type: boolean
  • Required: No
  • Default: false

<templateDir>

The directory holding the script templates.
  • Type: java.io.File
  • Required: No
  • Default: ${project.basedir}/templates

<updateTemplate>

The name of the update script template.
  • Type: java.lang.String
  • Required: No
  • Default: update.ftl

<variables>

Extra variables for template or artifact generation.

For example, the subproject's basedir:

 <variables>
   <project>${project.basedir}</project>
 </variables>
And then use it in package-image.ftl for file paths, such as:
  --icon ${project}/src/pkg/myapp.ico
  • Type: java.util.Map<java.lang.String, java.lang.Object>
  • Required: No

<variablesPrecedence>

Defines the precedence of properties and variables.
By default, system properties are overridden by maven properties which are overridden by the extra template variables.

The case-insensitive keywords are:

  • system, sys: for system properties
  • maven, mvn, properties, props, pom: maven properties
  • variables, vars, var, extras, extra, template: extra template variables
  • Type: java.lang.String
  • Required: Yes
  • Default: system, maven, variables

<verbosity>

The verbosity.
One of "default", "info" or "debug". Other values are treated as "default".
If not set, debug is turned on by Maven's global debug flag (see command line switch -X).
  • Type: java.lang.String
  • Required: No
  • Default: ${tentackle.verbosity}

<withUpdater>

Enables the auto-update feature.

For the jlink goal an extra update script will be generated via the JLinkMojo.getUpdateTemplate(). The update script will be named bin/update.<extension> where the extension is derived from the platform (cmd on Windows, otherwise sh for unixes).

For the jpackage goal an extra ZIP-file is created holding the jpackage image's files and an update script generated via getPackageUpdateTemplate().

For an implementation of the auto-update feature see the Tentackle modules tentackle-update and tentackle-fx-rdc-update. Whereas tentackle-update can be used by any kind of application, the frontend part tentackle-fx-rdc-update requires a Tentackle FX application.

  • Type: boolean
  • Required: No

<zipDirectory>

The directory where to store the ZIP files.
  • Type: java.io.File
  • Required: No
  • Default: ${project.build.directory}