Class JLinkMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.tentackle.maven.AbstractTentackleMojo
-
- org.tentackle.maven.plugin.jlink.AbstractJLinkMojo
-
- org.tentackle.maven.plugin.jlink.JLinkMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="jlink", requiresDependencyResolution=RUNTIME, defaultPhase=PACKAGE) public class JLinkMojo extends AbstractJLinkMojoCreates a self-contained java application with thejlinktool.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
jlinkto create a directory containing an application-specificjimagemodule. 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 mininum 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
jlinkare 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 therunTemplate. For applications using Tentackle's auto update feature, an update script is generated via theupdateTemplateas 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, seeJPackageMojo), useInitMojofirst.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
jlinkand automatic modules are copied to thempfolder and added to themodulePathtemplate variable. If no such modules are detected, no folder is created.
Non-modular classpath artifacts are copied to thecpfolder and added to theclassPathtemplate variable. Again, the folder is only created if necessary.
Additional project resources, such as property files or logger configurations, are copied to theconfdirectory 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
Fields Modifier and Type Field Description static java.lang.StringNAME_TEMPLATEfilename of the NAME template.static java.lang.StringRUN_TEMPLATEfilename of the RUN template.static java.lang.StringUPDATE_TEMPLATEfilename of the UPDATE template.-
Fields inherited from class org.tentackle.maven.plugin.jlink.AbstractJLinkMojo
DEST_CLASSPATH, DEST_MODULEPATH, DEST_RESOURCES, ZIP_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description JLinkMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecuteImpl()protected voidgenerateFiles(JLinkResolver.Result result)Generates additional files such as shell scripts or command files.java.lang.StringgetNameTemplate()Gets the name of the name template.java.lang.StringgetRunTemplate()Gets the name of the runner template.java.lang.StringgetUpdateTemplate()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, isWithUpdater, logToolOutput, prepareExecute
-
Methods inherited from class org.tentackle.maven.AbstractTentackleMojo
createPackageMap, determineEncoding, determineJavaToolVersion, determineVerbosity, execute, findResourceDirs, finishExecute, getCanonicalPath, getHostName, getMajorVersion, getMavenProject, getMavenSession, getMojoExecution, getPathRelativeToBasedir, getResourceDirName, getSettings, getSettingsDecrypter, getToolchain, getToolchain, getToolchain, getToolchainManager, getToolFinder, installJavaLoggingHandler, isExecutionRecursive, isSkippedByDefault, loadResourceFileIntoString
-
-
-
-
Field Detail
-
NAME_TEMPLATE
public static final java.lang.String NAME_TEMPLATE
filename of the NAME template.- See Also:
- Constant Field Values
-
RUN_TEMPLATE
public static final java.lang.String RUN_TEMPLATE
filename of the RUN template.- See Also:
- Constant Field Values
-
UPDATE_TEMPLATE
public static final java.lang.String UPDATE_TEMPLATE
filename of the UPDATE template.- See Also:
- Constant Field Values
-
-
Method Detail
-
getNameTemplate
public java.lang.String getNameTemplate()
Gets the name of the name template.- Returns:
- the template to generate the name of the runner script
-
getRunTemplate
public java.lang.String getRunTemplate()
Gets the name of the runner template.- Returns:
- the template to generate the runner script
-
getUpdateTemplate
public java.lang.String 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.MojoExecutionExceptionDescription 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
-
-