jlink

You can use the jlink tool to assemble and optimize a set of modules and their dependencies into a custom runtime image.

Synopsis

jlink [options] --module-path modulepath --add-modules module [,module...]
options

Command-line options separated by spaces. See jlink Options.

modulepath

The path where the jlink tool discovers observable modules. These modules can be modular JAR files, JMOD files, or exploded modules.

module

The names of the modules to add to the runtime image. The jlink tool adds these modules and their transitive dependencies.

Description

The jlink tool links a set of modules, along with their transitive dependences, to create a custom runtime image.

Note:

Developers are responsible for updating their custom runtime images.

Unlike custom runtime images, web-deployed Java applications automatically download application updates from the web as soon as they’re available. The Java Auto Update mechanism takes care of updating the JRE to the latest secure version several times every year. Custom runtime images don’t have built-in support for automatic updates.

jlink Options

--add-modules mod [,mod...]

Adds the named modules, mod, to the default set of root modules. The default set of root modules is empty.

--bind-services

Link service provider modules and their dependencies.

-c ={0|1|2} or --compress={0|1|2}

Enable compression of resources:

  • 0: No compression
  • 1: Constant string sharing
  • 2: ZIP
--disable-plugin pluginname

Disables the specified plug-in. See jlink Plug-ins for the list of supported plug-ins.

--endian {little|big}

Specifies the byte order of the generated image. The default value is the format of your system's architecture.

-h or --help

Prints the help message.

--ignore-signing-information

Suppresses a fatal error when signed modular JARs are linked in the runtime image. The signature-related files of the signed modular JARs aren’t copied to the runtime image.

--launcher command=module or --launcher command=module/main

Specifies the launcher command name for the module or the command name for the module and main class (the module and the main class names are separated by a slash (/)).

--limit-modules mod [,mod...]

Limits the universe of observable modules to those in the transitive closure of the named modules, mod, plus the main module, if any, plus any further modules specified in the --add-modules option.

--list-plugins

Lists available plug-ins, which you can access through command-line options; see jlink Plug-ins.

-p or --module-path modulepath

Specifies the module path.

--no-header-files

Excludes header files.

--no-man-pages

Excludes man pages.

--output path

Specifies the location of the generated runtime image.

--save-opts filename

Saves jlink options in the specified file.

--suggest-providers [name, ...]

Suggest providers that implement the given service types from the module path.

--version

Prints version information.

@filename

Reads options from the specified file.

An options file is a text file that contains the options and values that you would typically enter in a command prompt. Options may appear on one line or on several lines. You may not specify environment variables for path names. You may comment out lines by prefixing a hash symbol (#) to the beginning of the line.

The following is an example of an options file for the jlink command:

#Wed Dec 07 00:40:19 EST 2016
--module-path C:/Java/jdk9/jmods;mlib
--add-modules com.greetings
--output greetingsapp

jlink Plug-ins

Note:

Plug-ins not listed in this section aren’t supported and are subject to change.

For plug-in options that require a pattern-list, the value is a comma-separated list of elements, with each element using one the following forms:

  • glob-pattern
  • glob:glob-pattern
  • regex:regex-pattern
  • @filename
    • filename is the name of a file that contains patterns to be used, one pattern per line.

For a complete list of all available plug-ins, run the command jlink --list-plugins.

Table 2-4 List of Available jlink plugins

Plugin Name Option Description

class-for-name

--class-for-name

Class optimization, converts Class.forName calls to constant loads.

compress

--compress={0|1|2}[:filter=pattern-list]

Compresses all resources in the output image.

  • Level 0: No compression
  • Level 1: Constant string sharing
  • Level 2: ZIP

An optional pattern-list filter can be specified to list the pattern of files to include.

dedup-legal-notices

--dedup-legal-notices=[error-if-not-same-content]

De-duplicates all legal notices. If error-if-not-same-content is specified then it will be an error if two files of the same filename are different.

exclude-files

--exclude-files=pattern-list

Specifies files to exclude. such as:

--exclude-files=**.java,glob:/java.base/lib/client/** 

exclude-jmod-section

--exclude-jmod-section=section-name

Specifies a JMOD section to exclude where section-name is man or headers.

exclude-resources

--exclude-resources=pattern-list

Specify resources to exclude. such as:

--exclude-resources=**.jcov,glob:**/META-INF/**

generate-jli-classes

--generate-jli-classes=@filename[:ignore-version=<true|false>]

Specify a file listing the java.lang.invoke classes to pre-generate. By default, this plugin may use a built-in list of classes to pre-generate. If this plugin runs on a different runtime version than the image being created, then code generation will be disabled by default to guarantee correctness. Add ignore-version=true to override this behavior.

include-locales

--include-locales=langtag[,langtag]*

Includes the list of locales where langtag is a BCP 47 language tag. This option supports locale matching as defined in RFC 4647. Ensure that you add the module jdk.localedata when using this option.

Example:

--add-modules jdk.localedata --include-locales=en,ja,*-IN

order-resources

--order-resources=pattern-list

Orders the specified paths in priority order. If @filename is specified, then each line in pattern-list must be an exact match for the paths to be ordered.

Example:

--order-resources=**/module-info.class,@classlist,/java.base/java/lang/**

release-info

--release-info={file|add:key1=value1:key2=value2:...|del:key-list}

Loads, adds, or deletes release properties where:

  • file: Loads release properties from the specified file.
  • add: Adds specified properties to the release file. You can specify any number of key=value pairs.
  • del: Deletes the list of keys in the release file key-list.

strip-debug

--strip-debug

Strips debug information from the output image

strip-native-commands

--strip-native-commands

Excludes native commands (such as java/java.exe) from the image

system-modules

--system-modules=retainModuleTarget

Fast loads module descriptors (always enabled)

vm

--vm={client|server|minimal|all}

Selects the HotSpot VM in the output image. Default is all.

jlink Examples

The following command creates a runtime image in the directory greetingsapp. This command links the module com.greetings, whose module definition is contained in the directory mlib. The directory $JAVA_HOME/jmods contains java.base.jmod and the other standard and JDK modules.

jlink --module-path $JAVA_HOME/jmods:mlib --add-modules com.greetings --output greetingsapp

The following command lists the modules in the runtime image greetingsapp:

greetingsapp/bin/java --list-modules
com.greetings
java.base@9
java.logging@9
org.astro@1.0

The following command creates a runtime image in the directory compressedrt that’s stripped of debug symbols, uses compression to reduce space, and includes French language locale information:

jlink --module-path $JAVA_HOME/jmods --add-modules jdk.localedata --strip-debug --compress=2 --include-locales=fr --output compressedrt

The following example compares the size of the runtime image compressedrt with fr_rt, which isn’t stripped of debug symbols and doesn’t use compression:

jlink --module-path $JAVA_HOME/jmods --add-modules jdk.localedata --include-locales=fr --output fr_rt

du -sh ./compressedrt ./fr_rt
23M     ./compressedrt
36M     ./fr_rt

The following example lists the providers that implement java.security.Provider:

jlink --module-path $JAVA-HOME/jmods --suggest-providers java.security.Provider

Suggested providers:
   java.naming provides java.security.Provider used by java.base
   java.security.jgss provides java.security.Provider used by java.base
   java.security.sasl provides java.security.Provider used by java.base
   java.smartcardio provides java.security.Provider used by java.base
   java.xml.crypto provides java.security.Provider used by java.base
   jdk.crypto.cryptoki provides java.security.Provider used by java.base
   jdk.crypto.ec provides java.security.Provider used by java.base
   jdk.crypto.mscapi provides java.security.Provider used by java.base
   jdk.deploy provides java.security.Provider used by java.base
   jdk.security.jgss provides java.security.Provider used by java.base

The following example creates a custom runtime image named mybuild that includes only java.naming and jdk.crypto.cryptoki and their dependencies but no other providers. Note that these dependencies must exist in the module path:

jlink --module-path $JAVA_HOME/jmods --add-modules java.naming,jdk.crypto.cryptoki --output mybuild

The following command is similar to the one that creates a runtime image named greetingsapp, except that it will link the modules resolved from root modules with service binding; see the Configuration.resolveAndBind method.

jlink --module-path $JAVA_HOME/jmods:mlib --add-modules com.greetings --output greetingsapp --bind-services

The following command lists the modules in the runtime image greetingsapp created by this command:

greetingsapp/bin/java --list-modules
com.greetings
java.base@9
java.compiler@9
java.datatransfer@9
java.desktop@9
java.logging@9
java.management@9
java.management.rmi@9
java.naming@9
java.prefs@9
java.rmi@9
java.scripting@9
java.security.jgss@9
java.security.sasl@9
java.smartcardio@9
java.xml@9
java.xml.crypto@9
jdk.accessibility@9
jdk.charsets@9
jdk.compiler@9
jdk.crypto.cryptoki@9
jdk.crypto.ec@9
jdk.crypto.mscapi@9
jdk.deploy@9
jdk.dynalink@9
jdk.internal.opt@9
jdk.jartool@9
jdk.javadoc@9
jdk.jdeps@9
jdk.jlink@9
jdk.localedata@9
jdk.management@9
jdk.naming.dns@9
jdk.naming.rmi@9
jdk.scripting.nashorn@9
jdk.security.auth@9
jdk.security.jgss@9
jdk.unsupported@9
jdk.zipfs@9
org.astro@1.0