Beta Draft: 2017-03-28

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 mods --output path
options

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

modulepath

The path where jlink discovers observable modules; these can be modular JAR files, JMOD files, or exploded modules. See The module path in The State of the Module System.

mods

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

path

The directory that contains the resulting runtime image.

Description

The jlink tool links a set of modules, along with their transitive dependences, to create a custom runtime image; see JEP 220: Modular Run-Time Images.

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 are available. The Java Auto Update mechanism takes care of updating the JRE to the latest secure version several times every year. Custom runtime images do not 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.
--disable-plugin pluginname
Disables the plugin specified.
--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 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 are not 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 plugins, which you can access through command-line options; see jlink Plugins.
-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.
--version
Prints version information.
@filename
Reads options from the specified file.

An options file is a text file that contains the options and values you would typically type 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 prepending 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 Plugins

Note:

Plugins that are not listed in this section are not supported and are subject to change.

For plugins requiring a pattern-list, the value is a comma-separated list of elements, each element using one the following forms:

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

The following plugins are the most useful for developers. For a complete list of all available plugins, run the command jlink --list-plugins.

--class-for-name
Optimizes classes by converting Class.forName calls to constant loads.
-c or --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 specifies which files to include.
--exclude-files=pattern-list
Specifies files to exclude. Example:

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

--exclude-resources=pattern-list
Specifies resources to exclude. Example:

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

--generate-jli-classes=@filename
Takes a file hinting to jlink what java.lang.invoke classes to pre-generate. If you don't specify this flag, then jlink generates a default set of classes.
--include-locales=langtag[,langtag]*
Includes the list of locales; 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=pattern-list
Orders the specified paths in priority order. If @filename is specified, then each element 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={file|add:key1=value1:key2=value2:...|del:key-list}
Loads, adds, or deletes release properties.
  • 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.
-G or --strip-debug
Strips debug information from the output image.
--strip-native-commands
Excludes native commands (such as java or java.exe) from the image.
--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. It 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 creates a runtime image in the directory compressedrt that is 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 is not stripped of debug symbols and does not 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