sbt-native-packager
  • Introduction
    • Goals
    • Scope
    • Core Concepts
      • Format Plugins
      • Archetype Plugins
      • Mappings
      • Architecture
  • Getting Started
    • Setup
      • Native Tools
    • Your first package
      • Run the app
      • Create a package
  • Formats
    • Universal Plugin
      • Related Plugins
      • Requirements
      • Build
        • Required Settings
      • Configurations
      • Settings
      • Tasks
      • Customize
        • Universal Archive Options
        • Getting Started with Universal Packaging
        • Universal Conventions
        • Change/Remove Top Level Directory in Output
        • Skip packageDoc task on stage
        • MappingsHelper
        • Mapping Examples
    • Linux Plugin
      • Related Plugins
      • Build
        • Required Settings
      • Configurations
      • Settings
      • Customize
        • Package Mappings
        • The LinuxPackageMapping Models
        • Modifying Mappings in General
        • Add Mappings
        • Filter/Remove Mappings
        • Alter LinuxPackageMapping
        • Alter LinuxSymlinks
        • Add Empty Directories
        • Man Pages
    • Debian Plugin
      • Requirements
      • Build
        • Required Settings
        • JRE Dependencies
        • Native packaging
        • Java based packaging
      • Configurations
      • Settings
      • Tasks
      • Customize
        • Customizing Debian Metadata
        • Hook Actions into the Debian Package Lifecycle
        • Use a Different Castle Directory for your Control Scripts
    • Rpm Plugin
      • Requirements
      • Build
        • Required Settings
        • 1.0 or higher
        • 0.8 or lower
      • Configuration
      • Settings
        • Informational Settings
        • Dependency Settings
        • Meta Settings
        • Scriptlet Settings
        • SystemV Start Script Settings
      • Tasks
      • Customize
        • Rpm Prefix
        • rpmChangelogFile
        • Scriptlet Changes
        • Scriptlet Migration from 1.0.x
        • Jar Repackaging
        • Marking config files as noreplace
    • Docker Plugin
      • Requirements
      • Build
        • Required Settings
        • Spotify java based docker client
      • Configuration
      • Settings
        • Informational Settings
        • Environment Settings
        • Publishing Settings
      • Tasks
      • Customize
        • Docker Image Name and Version
        • Docker Base Image
        • Docker Repository
        • Docker Image Customization
        • Install Location
        • Daemon User
        • File Permission
        • Custom Dockerfile
        • Remove Commands
        • Add Commands
        • Write from Scratch
        • Busybox/Ash Support
        • Init support
    • Windows Plugin
      • Requirements
      • Build
        • Required Settings
        • 1.0 or higher
        • 0.8 or lower
      • Configuration
      • Settings
      • Tasks
      • Customize
        • Feature configuration
    • JDKPackager Plugin
      • Requirements
      • Enabling
      • Build
      • Settings
      • Example
      • Debugging
    • GraalVM Native Image Plugin
      • Requirements
        • native-image quick installation
      • Build
        • Required Settings
      • Settings
        • Docker Image Build Settings
        • Publishing Settings
      • GraalVM Resources
      • Tasks
  • Archetypes
    • Java Command Line Application
      • Features
      • Usage
      • Settings & Tasks
      • Start script options
      • Multiple Applications
        • Multiple start scripts
        • Single start script with forwarders
        • A note on script names
      • Customize
        • Application and runtime configuration
        • Start script customizations
        • Overriding Templates (Bash/Bat)
    • Java Server Application
      • Features
      • Usage
      • Settings & Tasks
      • Default Mappings
      • Customize
        • Application Configuration
        • Systemloader Configuration
        • Package Lifecycle Configuration
        • Example Configurations
    • Systemloaders
      • Overview
        • General Settings
      • SystemV
      • Systemd
        • Settings
      • Upstart
      • Customization
        • Start Script Location
        • Customize Start Script
        • Override Start Script
    • Configuration Archetypes
      • AshScript Plugin
      • ClasspathJar & LauncherJar Plugin
    • Jlink Plugin
      • Known issues
      • Further reading
    • An archetype cheatsheet
      • Path Configurations
        • Quick Reference Table
        • Settings
      • JVM Options
        • Extra Defines
        • File - application.ini or etc-default
        • Setting - javaOptions
      • Overriding Templates
        • Bat Script - src/templates/bat-template
        • Bash Script - src/templates/bash-template
        • Service Manager Templates
        • Server App Config - src/templates/etc-default-{systemv,systemd}
  • Recipes
    • Custom Package Formats
      • SBT Assembly
      • Proguard
      • Multi Module Builds
      • Custom Packaging Format
    • Dealing with long classpaths
      • Generate a launcher jar
      • Generate a classpath jar
      • Configure a wildcard classpath
    • Play 2 Packaging
      • Build Configuration
      • Application Configuration
        • SystemV
    • Deployment
      • Setup publish Task
      • Default Deployment
      • Custom Deployments
        • RPM
        • Debian
        • Windows
      • Custom Configurations
        • Debian
        • RPM
        • Windows
        • Universal
    • Scala JS packaging
      • Package webjars and scalajs resources
    • Build the same package with different configs
      • SBT sub modules
      • SBT parameters and Build Environment
      • SBT configuration scope (not recommended)
    • Embedding JVM in Universal
      • Adding the JVM
      • Application Configuration
    • Setting the umask for your process
      • Within the start script
      • System V/systemd
sbt-native-packager
  • Project Archetypes
  • Jlink Plugin
  • View page source

Jlink Plugin¶

This plugin builds on Java’s jlink tool to embed a JVM image (a stripped-down JRE) into your package. It produces a JVM image containing only the modules that are referenced from the dependency classpath.

Note: Current implementation only detects the platform modules (that is, the ones present in the JDK used to build the image). Modular JARs and directories are packaged as specified by the UniversalPlugin.

enablePlugins(JlinkPlugin)

The plugin requires Oracle JDK 11 or OpenJDK 11. Although jlink and jdeps are also a part of the older JDK versions, those lack some of the newer features, which was not addressed in the current plugin version.

This plugin must be run on the platform of the target installer. The tooling does not provide a means of creating, say, Windows installers on MacOS, or MacOS on Linux, etc.

The plugin analyzes the dependencies between packages using jdeps, and raises an error in case of a missing dependency (e.g. for a provided transitive dependency). The missing dependencies can be suppressed on a case-by-case basis (e.g. if you are sure the missing dependency is properly handled):

jlinkIgnoreMissingDependency := JlinkIgnore.only(
  "foo.bar" -> "bar.baz",
  "foo.bar" -> "bar.qux"
)

For large projects with a lot of dependencies this can get unwieldy. You can use a more flexible ignore strategy:

jlinkIgnoreMissingDependency := JlinkIgnore.byPackagePrefix(
  "foo.bar" -> "bar"
)

Otherwise you may opt out of the check altogether (which is not recommended):

jlinkIgnoreMissingDependency := JlinkIgnore.everything

Known issues¶

Adding some library dependencies can lead to errors like this:

java.lang.module.FindException: Module paranamer not found, required by com.fasterxml.jackson.module.paranamer

This is often caused by depending on automatic modules. In the example above, com.faterxml.jackson.module.paranamer is an explicit module (as in, it is a JAR with a module descriptor) that defines a dependency on the paranamer module. However, there is no explicit paranamer module - instead, Jackson expects us to use the paranamer JAR file as an automatic module. To do this, the JAR has to be on the module path. At the moment JlinkPlugin does not put it there automatically, so we have to do that ourselves:

jlinkModulePath := {
  // Get the full classpath with all the resolved dependencies.
  (jlinkBuildImage / fullClasspath).value
    // Find the ones that have `paranamer` as their names.
    .filter { item =>
      item.get(moduleID.key).exists { modId =>
        modId.name == "paranamer"
      }
    }
    // Get raw `File` objects.
    .map(_.data)
}

Further reading¶

For further details on the capabilities of jlink, see the jlink and jdeps references. (Note: only some of the possible settings are exposed through this plugin. Please submit a Github issue or pull request if something specific is desired.)

Previous Next

© Copyright 2014 sbt-native-packager team.

Built with Sphinx using a theme provided by Read the Docs.