• Logo
    Rockcraft
  • github.com/canonical/rockcraft
  • More resources
    • Discourse
    • GitHub
Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Rockcraft 1.9.0 documentation
Rockcraft 1.9.0 documentation
  • Tutorial
    • 1. Create a Hello World rock
    • 2. Install slices in a rock
    • 3. Containerise a PyPI package
    • 4. Bundle a Node.js app within a rock
    • 5. Build a rock for a Flask application
    • 6. Build a rock for a Django application
    • 7. Build a rock for a FastAPI application
    • 8. Build a rock for a Go application
  • How-to guides
    • Get started - quick guide
    • Build a 12-factor app rock
    • Outsource rock builds to Launchpad
    • Cut existing slices with Chisel
    • Create a package slice for Chisel
    • Install a custom package slice
    • Publish a slice definition
    • Contribute to Rockcraft documentation
    • Build the documentation
    • Use Rockcraft's GitHub Action
    • Convert an entrypoint to a Pebble layer
    • Add a new internal user to a rock
    • Publish a rock to a registry
    • Migrate a Docker image to a chiselled rock
    • Chisel an existing rock
    • Include local and remote files
    • Override a plugin's build
  • Reference
    • rockcraft.yaml
      • Part properties
    • Rockcraft commands
      • build
      • clean
      • expand-extensions
      • extensions
      • init
      • list-extensions
      • pack
      • prime
      • pull
      • remote-build
      • stage
      • version
    • Extensions
      • flask-framework
      • django-framework
      • fastapi-framework
      • go-framework
    • Rockcraft plugins
      • .NET plugin
      • Ant plugin
      • Autotools plugin
      • CMake plugin
      • Dump plugin
      • Go plugin
      • Go Use plugin
      • JLink plugin
      • Make plugin
      • Maven plugin
      • Meson plugin
      • Nil plugin
      • NPM Plugin
      • Poetry plugin
      • Python plugin
      • Qmake plugin
      • Rust plugin
      • SCons plugin
      • uv plugin
    • Parts and Steps
    • Remote builds
    • Changelog
  • Explanation
    • Why use Rockcraft?
    • Chisel
    • Overlay step
    • Rocks
    • Bases
    • Pebble
    • From prime step to OCI layer
    • Filesets
    • Parts
    • Lifecycle details
    • Dump Plugin
  • Release notes
    • Rockcraft 1.9.0
    • Rockcraft 1.8.0
    • Rockcraft 1.7.0
Back to top
View 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.

Keywords¶

This plugin uses the common plugin keywords as well as those for sources.

Additionally, this plugin provides the plugin-specific keywords defined in the following sections.

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.

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.

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:

  • Finds all JAR files in the staging area or selects jars specified in jlink-jars.

  • Unpacks JAR files to the temporary location and concatenates all embedded jars into jdeps classpath.

  • Runs jdeps to discover Java modules required for the staged jars.

  • Runs jlink to create a runtime image from the build JDK.

Copyright © 2022-2025, Canonical Group Ltd
Last updated on Feb 28, 2025
Show source
Ask a question on Discourse
Open a GitHub issue for this page
Edit this page on GitHub
Contents
  • JLink plugin
    • Keywords
      • jlink-jars
    • Dependencies
    • How it works