tentackle-jlink:jlink
Full name:
org.tentackle:tentackle-jlink-maven-plugin:21.16.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:
- 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.
- 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. - Non-modular traditional classpath applications: same as 2, but all dependencies are placed on the classpath.
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 pathphase
: the mojo lifecycle phasegoal
: the plugin goal (jlink or jpackage)id
: the execution id- 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()
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 specifying an explicit AbstractJLinkMojo#getToolchain()
.
Attributes:
- Requires a Maven project to be executed.
- Requires dependency resolution of artifacts in scope:
runtime
. - The goal is not marked as thread-safe and thus does not support 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:
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 bin. Example: <addModules> <addModule>jdk.localedata</addModule> <addModule>jdk.jcmd</addModule> </addModules> |
<charset> |
String |
- |
The encoding to read and write files. Default: ${project.build.sourceEncoding} |
<classpathDependencies> |
List<ClasspathDependency> |
- |
Dependencies that should go to the classpath instead of modulepath. |
<compress> |
Integer |
- |
Compression of resources.
Corresponds to the jlink option --compress . |
<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> |
<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. |
<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>14</version> </jdkToolchain>To deselect the toolchain configured by the maven-toolchain-plugin: <jdkToolchain></jdkToolchain> |
<jlinkTool> |
File |
- |
Explicit path to the jlink tool.
Only if toolchains cannot be used. See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain() User Property: jlinkTool |
<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.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 it 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. If all modules must be moved to the Examples: <modulePathOnly> <module>tentackle.log.log4j2v</module> <module>org.apache.logging.log4j</module> </modulePathOnly>or <modulePathOnly>all</modulePathOnly> |
<nameTemplate> |
String |
- |
The name of the template to generate the name of the runner script.
For *nixes this is usually run.sh , for windozes run.cmd or run.bat .Default: name.ftl |
<noHeaderFiles> |
boolean |
- |
Suppress the includes 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.
Defaults to true if packaging is "pom". |
<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". Debug is also turned on (if not set explicitly) by Maven's global debug flag (see command line switch -X ).Default: ${tentackle.verbosity} |
<withUpdater> |
boolean |
- |
Enables the auto update feature.
For the For the For an implementation of the auto-update feature see the Tentackle modules |
<zipDirectory> |
File |
- |
The directory where to store the ZIP files. Default: ${project.build.directory} |
Parameter Details
<addModules>
Useful to add the runtime localization module or extra tools in bin.
Example:
<addModules> <addModule>jdk.localedata</addModule> <addModule>jdk.jcmd</addModule> </addModules>
- Type:
java.util.List<java.lang.String>
- Required:
No
<charset>
- Type:
java.lang.String
- Required:
No
- Default:
${project.build.sourceEncoding}
<classpathDependencies>
- Type:
java.util.List<org.tentackle.maven.plugin.jlink.ClasspathDependency>
- Required:
No
<compress>
Corresponds to the
jlink
option --compress
.- Type:
java.lang.Integer
- Required:
No
<excludeModules>
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
<extraClassifier>
- Type:
java.lang.String
- Required:
No
<extraClasspathElements>
Pathnames are relative to the image root.
- Type:
java.util.List<java.lang.String>
- Required:
No
<extraDirectories>
- Type:
java.util.List<java.io.File>
- Required:
No
<ignoreSigningInformation>
Corresponds to the
jlink
option --ignore-signing-information
- Type:
boolean
- Required:
No
- Default:
false
<imageDirectory>
- Type:
java.io.File
- Required:
Yes
- Default:
${project.build.directory}/jlink
<jdepsTool>
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>
Explicitly specifies the
"jdk"
toolchain for this plugin only. Overrides the toolchain selected by the maven-toolchain-plugin, if any.
Example:
<jdkToolchain> <version>14</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
<jlinkTool>
jlink
tool.
Only if toolchains cannot be used.
See also: org.tentackle.maven.AbstractTentackleMojo.getToolchain()
- Type:
java.io.File
- Required:
No
- User Property:
jlinkTool
<mainClass>
- Type:
java.lang.String
- Required:
Yes
<mainModule>
If missing, the plugin will build an application running on the classpath.
- Type:
java.lang.String
- Required:
No
<minLogLevel>
java.util.logging.Level
to redirect java.util logging to the maven logger.- Type:
java.lang.String
- Required:
No
- Default:
WARNING
<modulePathOnly>
By default, all full-blown modules are passed to the jlink tool. If a module is listed for the module path only, the module it 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.
If all modules must be moved to the mp
folder, the single values true
, all
or *
can be used as a shortcut.
Examples:
<modulePathOnly> <module>tentackle.log.log4j2v</module> <module>org.apache.logging.log4j</module> </modulePathOnly>or
<modulePathOnly>all</modulePathOnly>
- Type:
java.util.List<java.lang.String>
- Required:
No
<nameTemplate>
For *nixes this is usually
run.sh
, for windozes run.cmd
or run.bat
.- Type:
java.lang.String
- Required:
No
- Default:
name.ftl
<noHeaderFiles>
includes
directory.
Corresponds to the
jlink
option --no-header-files
.- Type:
boolean
- Required:
No
- Default:
false
<noManPages>
man
directory.
Corresponds to the
jlink
option --no-man-pages
- Type:
boolean
- Required:
No
- Default:
false
<resourcesDirectory>
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>
- Type:
java.lang.String
- Required:
No
- Default:
run.ftl
<saveOpts>
Corresponds to the
jlink
option --save-opts
.- Type:
java.io.File
- Required:
No
<skip>
Defaults to true if packaging is "pom".
- Type:
java.lang.Boolean
- Required:
No
<stripDebug>
Corresponds to the
jlink
option --strip-debug
.- Type:
boolean
- Required:
No
- Default:
false
<templateDir>
- Type:
java.io.File
- Required:
No
- Default:
${project.basedir}/templates
<updateTemplate>
- Type:
java.lang.String
- Required:
No
- Default:
update.ftl
<variables>
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>
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 propertiesmaven, mvn, properties, props, pom
: maven propertiesvariables, vars, var, extras, extra, template
: extra template variables
- Type:
java.lang.String
- Required:
Yes
- Default:
system, maven, variables
<verbosity>
One of "default", "info" or "debug". Debug is also turned on (if not set explicitly) by Maven's global debug flag (see command line switch
-X
).- Type:
java.lang.String
- Required:
No
- Default:
${tentackle.verbosity}
<withUpdater>
For the jlink
gaol 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>
- Type:
java.io.File
- Required:
No
- Default:
${project.build.directory}