Class JLinkMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
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
jdepstool. 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
AbstractJLinkMojo.variables
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 is only created if necessary.Additional project resources, such as property files or logger configurations, are copied to the
conf directory and
this directory is 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 AbstractTentackleMojo.jdkToolchain.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringfilename of the NAME template.static final Stringfilename of the RUN template.static final Stringfilename of the UPDATE template.Fields inherited from class org.tentackle.maven.plugin.jlink.AbstractJLinkMojo
DEST_CLASSPATH, DEST_MODULEPATH, DEST_RESOURCES, ZIP_EXTENSIONFields inherited from class org.tentackle.maven.AbstractTentackleMojo
charset, JDK_TOOLCHAIN, minLogLevel, verbosity, verbosityLevelFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidgenerateFiles(JLinkResolver.Result result) Generates additional files such as shell scripts or command files.Gets the name of the name template.Gets the name of the runner template.Gets the name of the update template.protected voidinstallTemplates(boolean overwrite) Copies the templates to the template directory.protected booleanvalidate()Methods inherited from class org.tentackle.maven.plugin.jlink.AbstractJLinkMojo
copyArtifacts, copyExtraDirectories, copyResources, createImage, createJLinkImage, createZipFile, getAddModules, getClassifier, getExcludeModules, getExtraClassifier, getExtraClasspathElements, getExtraDirectories, getFinalName, getImageDirectory, getImagePathPrefix, getJavaMajorRuntimeVersion, getJavaRuntimeVersion, getJdepsTool, getLocationManager, getMainClass, getMainModule, getProjectHelper, getTemplateDir, getVariables, getVariablesPrecedence, getZipDirectory, installTemplate, isClasspathDependency, isModulePathOnly, isModulePathOnly, isWithUpdater, logToolOutput, prepareExecuteMethods inherited from class org.tentackle.maven.AbstractTentackleMojo
createPackageMap, determineEncoding, determineJavaToolVersion, determineVerbosity, execute, finishExecute, getCanonicalPath, getHostName, getMajorVersion, getMavenProject, getMavenSession, getMojoExecution, getPathRelativeToBasedir, getResourceDir, getResourceDirs, getSettings, getSettingsDecrypter, getToolchain, getToolchain, getToolchain, getToolchainManager, getToolFinder, installJavaLoggingHandler, isExecutionRecursive, isSkippedByDefault, loadResourceFileIntoString, toDescriptorNameMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
NAME_TEMPLATE
filename of the NAME template.- See Also:
-
RUN_TEMPLATE
filename of the RUN template.- See Also:
-
UPDATE_TEMPLATE
filename of the UPDATE template.- See Also:
-
-
Constructor Details
-
JLinkMojo
public JLinkMojo()
-
-
Method Details
-
getNameTemplate
Gets the name of the name template.- Returns:
- the template to generate the name of the runner script
-
getRunTemplate
Gets the name of the runner template.- Returns:
- the template to generate the runner script
-
getUpdateTemplate
Gets the name of the update template.- Returns:
- the template to generate the update script, null if don't generate an update script
-
executeImpl
public void executeImpl() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Overrides:
executeImplin classAbstractJLinkMojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
generateFiles
protected void generateFiles(JLinkResolver.Result result) throws org.apache.maven.plugin.MojoExecutionException Description copied from class:AbstractJLinkMojoGenerates additional files such as shell scripts or command files.- Specified by:
generateFilesin classAbstractJLinkMojo- Parameters:
result- the resolver result- Throws:
org.apache.maven.plugin.MojoExecutionException- if generation failed
-
validate
protected boolean validate() throws org.apache.maven.plugin.MojoExecutionException- Overrides:
validatein classAbstractJLinkMojo- Throws:
org.apache.maven.plugin.MojoExecutionException
-
installTemplates
protected void installTemplates(boolean overwrite) throws org.apache.maven.plugin.MojoExecutionException Description copied from class:AbstractJLinkMojoCopies the templates to the template directory.- Specified by:
installTemplatesin classAbstractJLinkMojo- Parameters:
overwrite- true if overwrite existing templates, false if install only missing- Throws:
org.apache.maven.plugin.MojoExecutionException- if installation failed
-