• Logo
    Craft Parts
  • github.com/canonical/craft-parts
  • More resources
    • Forum
    • GitHub
Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Craft Parts documentation
Craft Parts documentation
  • Tutorials
    • Adding parts processing to an application
    • Hello craft-parts
  • How-to guides
    • Use parts
    • Customise the build with craftctl
    • Use craft-parts from the command-line
    • Override a part's default build behavior
    • Create a plugin
    • Document a plugin
    • Including local files and remote resources
    • Add a custom source type to an application
  • Reference
    • Actions
    • Exceptions
    • Project information
    • Lifecycle manager
    • Part properties
    • Parts and Steps
    • Plugins
      • .NET plugin
      • Ant plugin
      • Autotools plugin
      • CMake plugin
      • Dump plugin
      • Go plugin
      • Go Use plugin
      • Gradle plugin
      • JLink plugin
      • Make plugin
      • Maven plugin
      • Meson plugin
      • Nil plugin
      • NPM Plugin
      • Poetry plugin
      • Python plugin
      • Qmake plugin
      • Cargo Use plugin
      • Rust plugin
      • SCons plugin
      • uv plugin
    • Package reference
      • craft_parts package
        • craft_parts.executor package
          • craft_parts.executor.collisions module
          • craft_parts.executor.environment module
          • craft_parts.executor.executor module
          • craft_parts.executor.filesets module
          • craft_parts.executor.migration module
          • craft_parts.executor.organize module
          • craft_parts.executor.part_handler module
          • craft_parts.executor.step_handler module
        • craft_parts.overlays package
          • craft_parts.overlays.chroot module
          • craft_parts.overlays.errors module
          • craft_parts.overlays.layers module
          • craft_parts.overlays.overlay_fs module
          • craft_parts.overlays.overlay_manager module
          • craft_parts.overlays.overlays module
        • craft_parts.packages package
          • craft_parts.packages.apt_cache module
          • craft_parts.packages.base module
          • craft_parts.packages.deb module
          • craft_parts.packages.deb_package module
          • craft_parts.packages.dnf module
          • craft_parts.packages.errors module
          • craft_parts.packages.normalize module
          • craft_parts.packages.platform module
          • craft_parts.packages.snaps module
          • craft_parts.packages.yum module
        • craft_parts.plugins package
          • craft_parts.plugins.ant_plugin module
          • craft_parts.plugins.autotools_plugin module
          • craft_parts.plugins.base module
          • craft_parts.plugins.cargo_use_plugin module
          • craft_parts.plugins.cmake_plugin module
          • craft_parts.plugins.dotnet_plugin module
          • craft_parts.plugins.dump_plugin module
          • craft_parts.plugins.go_plugin module
          • craft_parts.plugins.go_use_plugin module
          • craft_parts.plugins.gradle_plugin module
          • craft_parts.plugins.java_plugin module
          • craft_parts.plugins.jlink_plugin module
          • craft_parts.plugins.make_plugin module
          • craft_parts.plugins.maven_plugin module
          • craft_parts.plugins.meson_plugin module
          • craft_parts.plugins.nil_plugin module
          • craft_parts.plugins.npm_plugin module
          • craft_parts.plugins.plugins module
          • craft_parts.plugins.poetry_plugin module
          • craft_parts.plugins.properties module
          • craft_parts.plugins.python_plugin module
          • craft_parts.plugins.qmake_plugin module
          • craft_parts.plugins.rust_plugin module
          • craft_parts.plugins.scons_plugin module
          • craft_parts.plugins.uv_plugin module
          • craft_parts.plugins.validator module
        • craft_parts.sources package
          • craft_parts.sources.base module
          • craft_parts.sources.cache module
          • craft_parts.sources.checksum module
          • craft_parts.sources.deb_source module
          • craft_parts.sources.errors module
          • craft_parts.sources.file_source module
          • craft_parts.sources.git_source module
          • craft_parts.sources.local_source module
          • craft_parts.sources.rpm_source module
          • craft_parts.sources.sevenzip_source module
          • craft_parts.sources.snap_source module
          • craft_parts.sources.sources module
          • craft_parts.sources.tar_source module
          • craft_parts.sources.zip_source module
        • craft_parts.state_manager package
          • craft_parts.state_manager.build_state module
          • craft_parts.state_manager.overlay_state module
          • craft_parts.state_manager.prime_state module
          • craft_parts.state_manager.pull_state module
          • craft_parts.state_manager.reports module
          • craft_parts.state_manager.stage_state module
          • craft_parts.state_manager.state_manager module
          • craft_parts.state_manager.states module
          • craft_parts.state_manager.step_state module
        • craft_parts.utils package
          • craft_parts.utils.deb_utils module
          • craft_parts.utils.file_utils module
          • craft_parts.utils.formatting_utils module
          • craft_parts.utils.git module
          • craft_parts.utils.os_utils module
          • craft_parts.utils.partition_utils module
          • craft_parts.utils.path_utils module
          • craft_parts.utils.process module
          • craft_parts.utils.url_utils module
        • craft_parts.actions module
        • craft_parts.callbacks module
        • craft_parts.constraints module
        • craft_parts.ctl module
        • craft_parts.dirs module
        • craft_parts.errors module
        • craft_parts.features module
        • craft_parts.infos module
        • craft_parts.lifecycle_manager module
        • craft_parts.main module
        • craft_parts.parts module
        • craft_parts.permissions module
        • craft_parts.pydantic_schema module
        • craft_parts.sequencer module
        • craft_parts.steps module
        • craft_parts.xattrs module
    • Changelog
  • Explanation
    • Parts
    • Lifecycle details
    • Implementation notes
    • Filesets
    • Overlay Step
    • Dump Plugin
    • Gradle Plugin
    • Cryptographic technology
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 © 2023-2025, Canonical Group Ltd
Last updated on May 08, 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