Search code examples
javajlink

How to set VM options for JLink launcher executable


When using jlink, a bin/java file is generated. This executable will accept VM options by specifying options on the command line in the usual way (such as -Dsystem.property=value or -Xmx1G).

jlink also provides a --launcher option to create an executable that can be run directly, instead of having to invoke the bin/java executable with a module name.

How do I make the launcher executable pre-configured to use my choice of JVM options?


Solution

  • You can use the add-options jlink plugin.

    For example, if you want to set Xmx:

    jlink --add-options="-Xmx100m" ...
    

    To see a list of jlink plugins, run jlink --list-plugins.

    The add-options plugin is currently documented (JDK14) as follows:

    Plugin Name: add-options
    Option: --add-options=<options>
    Description: Prepend the specified <options> string, which may include
    whitespace, before any other options when invoking the virtual machine
    in the resulting image.
    

    Beware that some of the plugins are, apparently, unstable (including add-options): https://docs.oracle.com/en/java/javase/12/tools/jlink.html