Course contentsShow
← Java
Lesson 2549 of 2,87047. Java Platform Module System (JPMS)Free lesson

The --launcher Option: Bundling Executables

Creating platform-specific launcher scripts automatically with --launcher for convenient application execution.

The --launcher Option: Bundling Executables

You'll learn how to embed platform-specific launcher scripts directly into your custom runtime image for instant application execution.

When you create a custom runtime image with jlink, you typically need to run your application using the bin/java executable with specific module and class parameters. The --launcher option eliminates this complexity by generating a convenient, ready-to-run launcher script bundled right into your runtime image.

How --launcher Works

Think of --launcher as creating a personalized shortcut that "remembers" exactly how to start your application. Instead of typing:

my-image/bin/java -m mymodule/com.example.Main

You create a simple command like:

my-image/bin/myapp

The launcher is platform-specific (a shell script on Unix/Linux, a batch file on Windows), automatically generated by jlink and placed in the image's bin directory.

Basic Syntax

jlink --module-path $MODULE_PATH \
      --add-modules mymodule \
      --launcher myapp=mymodule/com.example.Main \
      --output my-image

The format is: --launcher <name>=<module>/<main-class>

  • <name>: What you want to call the launcher (e.g., "myapp")
  • <module>: The module containing your main class
  • <main-class>: Fully-qualified class name with the main method

You can create multiple launchers in one image by repeating the --launcher option, useful if your application has multiple entry points (like a server mode and a configuration tool).

Key Takeaway: The --launcher option packages platform-specific executable scripts into your runtime image, providing users with a simple, one-command way to run your application without requiring knowledge of module paths or main classes.