• Logo
    Rockcraft
  • More resources
    • Discourse
    • Matrix
    • GitHub
Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Rockcraft dev documentation
Rockcraft dev documentation
  • Tutorial
    • Create a “Hello World” rock
    • Pack a Python package
    • Bundle a Node.js app into a rock
    • Shrink a rock with Chisel
    • Build a rock for a Flask app
    • Build a rock for a Django app
    • Build a rock for a FastAPI app
    • Build a rock for a Go app
    • Build a rock for an Express app
    • Build a rock for a Spring Boot app
  • How-to guides
    • Quickstart guide
    • Crafting
      • Migrate a Docker image to a chiselled rock
      • Specify a base
      • Convert an entrypoint to a Pebble layer
      • Add an internal user
      • Including local files and remote resources
      • Override a plugin's build
      • Publish a rock to a registry
      • Use the Rockcraft Pack GitHub Action
      • Outsource rock builds to Launchpad
    • Chiselling
      • Chisel a rock
      • Cut existing slices
      • Create a package slice for Chisel
      • Install a custom package slice
      • Publish a slice definition
    • Rocks for 12-factor apps
      • Set up a 12-Factor app rock
      • Use a 12-factor app rock
      • Configure the build base for an Express app
    • Documentation
      • Contribute to Rockcraft documentation
      • Build the documentation
  • Reference
    • rockcraft.yaml
      • Part properties
    • Commands
      • build
      • clean
      • expand-extensions
      • extensions
      • init
      • list-extensions
      • pack
      • prime
      • pull
      • remote-build
      • stage
      • test
      • version
    • Extensions
      • Flask framework
      • Django framework
      • FastAPI framework
      • Go framework
      • Express framework
      • Sprint Boot framework
      • Project requirements
      • parts > spring-boot-framework/install-app > plugin
      • parts > spring-boot-framework/install-app > build-packages
      • parts > spring-boot-framework/runtime
      • parts > spring-boot-framework/assets > stage
      • Useful links
    • Rockcraft plugins
      • .NET plugin
      • .NET plugin (v2)
      • Ant plugin
      • Autotools plugin
      • Cargo Use plugin
      • CMake plugin
      • Dump plugin
      • Go plugin
      • Go Use plugin
      • Gradle plugin
      • JLink plugin
      • Make plugin
      • Maven plugin
      • Maven Use plugin
      • Meson plugin
      • Nil plugin
      • NPM Plugin
      • Poetry plugin
      • Python plugin ([email protected])
      • Python plugin ([email protected])
      • Qmake plugin
      • Rust plugin
      • SCons plugin
      • uv plugin
    • Parts and Steps
    • Remote builds
    • Changelog
  • Explanation
    • Cryptographic technology
    • Why use Rockcraft?
    • Chisel
    • Overlay step
    • Rocks
    • Bases
    • Pebble
    • From prime step to OCI layer
    • Filesets
    • Parts
    • Lifecycle details
    • Dump Plugin
    • Usrmerge implementation
  • Contribute to this documentation
  • Release notes
    • Rockcraft 1.15
    • Rockcraft 1.14
    • Rockcraft 1.13
    • Rockcraft 1.12
    • Rockcraft 1.11
    • Rockcraft 1.10
    • Rockcraft 1.9
    • Rockcraft 1.8
    • Rockcraft 1.7
Back to top
Contribute to this page

JLink plugin¶

The JLink plugin can be used for Java projects where you would want to deploy a Java runtime specific for your application or install a minimal Java runtime.

Keys¶

This plugin provides the following unique keys.

jlink-jars¶

Type: list of strings

List of paths to your application’s JAR files. If not specified, the plugin will find all JAR files in the staging area.

jlink-extra-modules¶

Type: list of strings

Additional modules to include in the OpenJDK image.

Dependencies¶

The plugin expects OpenJDK to be available on the system and to contain the jlink executable. OpenJDK can be defined as a build-package in the part using jlink plugin. Another alternative is to define another part with the name jlink-deps, and declare that the part using the jlink plugin comes after the jlink-deps part through the after key.

If the system has multiple OpenJDK installations available, one must be selected by setting the JAVA_HOME environment variable.

parts:
  runtime:
    plugin: jlink
    build-packages:
      - openjdk-21-jdk
    build-environment:
      - JAVA_HOME: /usr/jvm/java-21-openjdk-${CRAFT_ARCH_BUILD_FOR}

The user is expected to stage OpenJDK dependencies either by installing an appropriate OpenJDK slice:

parts:
  runtime:
    plugin: jlink
    build-packages:
      - openjdk-21-jdk
    after:
      - deps

    deps:
      plugin: nil
      stage-packages:
        - openjdk-21-jre-headless_security
      stage:
        - -usr/lib/jvm

Or, by installing the dependencies directly:

parts:
  runtime:
    plugin: jlink
    build-packages:
      - openjdk-21-jdk
    after:
      - deps

  deps:
    plugin: nil
    stage-packages:
      - libc6_libs
      - libgcc-s1_libs
      - libstdc++6_libs
      - zlib1g_libs
      - libnss3_libs

How it works¶

During the build step, the plugin performs the following actions:

  1. Find all JAR files in the staging area or selects jars specified in jlink-jars.

  2. Unpack JAR files to the temporary location and concatenate all embedded jars into jdeps classpath.

  3. Run jdeps to discover Java modules required for the staged jars.

  4. Run jlink to create a runtime image from the build JDK.

Copyright © 2022-2025, Canonical Group Ltd
Last updated on Oct 31, 2025
Manage your tracker settings
Contents
  • JLink plugin
    • Keys
      • jlink-jars
      • jlink-extra-modules
    • Dependencies
    • How it works