• Logo
    Snapcraft
  • snapcraft.io
  • 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
Snapcraft 8.8.1 documentation
Snapcraft 8.8.1 documentation
  • Tutorials
  • How-to guides
    • Set up Snapcraft
    • Select a build provider
    • Craft a snap
      • Example pre-built app
      • Example Python app
      • Example C or C++ app
      • Example Java app
      • Example Go app
      • Example Rust app
      • Example Node app
      • Example Ruby app
      • Example GTK4 app
      • Example GTK3 app
      • Example GTK2 app
      • Example Qt5 KDE app
      • Example cross-compiled app
      • Example Flutter app
      • Example Electron apps
      • Example .NET app
      • Example MOOS app
      • Example ROS 2 app
      • Example ROS 1 app
    • Architectures
    • Bases
    • How to package and upload a snap with components
    • Use extensions
      • Use an extension
      • List extensions
      • Enable experimental extensions
      • Use the env-injector extension
      • Use the GNOME extension
    • Including local files and remote resources
    • Overriding the default build
  • Reference
    • Anatomy of a project file
    • Snap build process
    • Snap publishing process
    • Channels
    • Architectures
    • Bases
    • Snapcraft commands
      • build
      • clean
      • close
      • create-key
      • edit-confdbs
      • edit-validation-sets
      • expand-extensions
      • export-login
      • extensions
      • gated
      • init
      • lint
      • list
      • list-confdbs
      • list-extensions
      • list-keys
      • list-plugins
      • list-registered
      • list-revisions
      • list-tracks
      • list-validation-sets
      • login
      • logout
      • metrics
      • names
      • pack
      • plugins
      • prime
      • promote
      • pull
      • push
      • register
      • register-key
      • release
      • remote-build
      • revisions
      • set-default-track
      • sign-build
      • snap
      • stage
      • status
      • tracks
      • try
      • upload
      • upload-metadata
      • validate
      • version
      • whoami
    • Components
    • Linters
    • Snapcraft 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
    • Extensions
      • env-injector extension
      • GNOME extension
      • KDE neon extensions
      • Flutter extension
      • ROS 1 extension
      • ROS 1 Content extensions
      • ROS 2 extensions
      • ROS 2 Content extensions
    • Part properties
    • Parts and Steps
    • System requirements
  • Explanation
    • Architectures
    • Bases
    • Components
    • Remote build
    • Filesets
    • Parts
    • Lifecycle details
    • Dump Plugin
  • Release notes
    • Snapcraft 8.8
    • Snapcraft 8.7
    • Changelog
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.

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 © 2025, Canonical Group Ltd
Last updated on Apr 21, 2025
Contents
  • JLink plugin
    • Keywords
      • jlink-jars
    • Dependencies
    • How it works