Package org.tentackle.maven.plugin.jlink
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, requiresProject=true) public class JlinkMojo extends AbstractJlinkMojoCreates a self-contained java application zip-file withjlink.
This mojo works for modular, non-modular and even mixed applications. It does so by analyzing the dependencies and finding the best strategy to invokejlink, which creates a directory containing an application-specificjimagemodule.
Artifacts not processed byjlinkare copied to separate folders. Next, a platform-specific run-script will be generated according to a template provided by the project. Finally, the created directory is packed into a zip file.Basically, applications fall into one of 3 categories:
- full-blown modular applications: all module-infos must only require real modules. Jlink is used to create an image from the application modules. Optional (but not required!) real and automatic modules are allowed and will be added to the module path via the generated run-script.
- modular applications with non-modular dependencies: jlink is used to create an image from java's runtime modules only,
which are determined by the plugin either from the module-infos or via
jdeps. The application's dependencies are placed on the module-path via the generated run-script. - non-modular applications: same as 2, but all dependencies are placed on the classpath.
<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 it does not exist, i.e. when the goal is invoked the first time. They become part of the project and can be changed easily according to project specific needs (for example by adding runtime arguments). 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 pathgoal: the plugin goal (jlink or jpackage)- all system properties (dots in property names translated to camelCase, e.g. "os.name" becomes "osName"
- all maven properties (translated to camelCase as well)
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 resources, such as property files or logger configurations, are copied to theconfdirectory and this directory is added to the classpath.
-
-
Constructor Summary
Constructors Constructor Description JlinkMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcreateImage(JlinkResolver.Result result)Creates the jlink image.voidexecuteImpl()java.io.FilegetImageDirectory()Gets the directory created by jlink holding the image.voidprepareExecute()protected booleanvalidate()-
Methods inherited from class org.tentackle.maven.plugin.jlink.AbstractJlinkMojo
copyArtifacts, getAddModules, getApplicationDirectory, getExcludeModules, getJdepsTool, getLocationManager, getMainClass, getMainModule, getNameTemplate, getProjectHelper, getRunTemplate, getTemplateDir, getUpdateTemplate, installTemplates, isClasspathDependency
-
Methods inherited from class org.tentackle.maven.AbstractTentackleMojo
determineEncoding, determineVerbosity, execute, findResourceDirs, finishExecute, getCanonicalPath, getMavenProject, getMavenSession, getPathRelativeToBasedir, getResourceDirName, getSettings, getSettingsDecrypter, getToolChain, getToolchainManager, getToolFinder, loadResourceFileIntoString
-
-
-
-
Method Detail
-
getImageDirectory
public java.io.File getImageDirectory()
Gets the directory created by jlink holding the image.- Specified by:
getImageDirectoryin classAbstractJlinkMojo- Returns:
- the image dir, never null
-
prepareExecute
public void prepareExecute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Overrides:
prepareExecutein classAbstractJlinkMojo- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
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
-
createImage
protected void createImage(JlinkResolver.Result result) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
Creates the jlink image.- Specified by:
createImagein classAbstractJlinkMojo- Parameters:
result- the resolver info- Throws:
org.apache.maven.plugin.MojoExecutionException- if building the JPMS info failedorg.apache.maven.plugin.MojoFailureException- if jlink returned an error code
-
validate
protected boolean validate() throws org.apache.maven.plugin.MojoExecutionException- Overrides:
validatein classAbstractJlinkMojo- Throws:
org.apache.maven.plugin.MojoExecutionException
-
-