JDK-8213087 : CSR for JEP 343: Packaging Tool (Incubator)
  • Type: CSR
  • Component: tools
  • Sub-Component: jpackage
  • Priority: P2
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2018-10-29
  • Updated: 2019-12-05
  • Resolved: 2019-12-05
Related Reports
Blocks :  
CSR :  
Relates :  
Description
Summary
-------

Create a new tool, jpackage, for packaging self-contained Java applications.

Problem
-------

Many Java applications need to be installed on a native platform in a first-class way, rather than simply being placed on the class path or the module path. It is not sufficient for the application developer to deliver a simple JAR file; they must deliver an installable package suitable for the native platform. This allows Java applications to be distributed, installed, and uninstalled in a manner that is familiar to users of that platform. For example, on Windows users expect to be able to double-click on an installer to install their software, and then use the control panel to remove the software; on macOS users expect to be able to double-click on a DMG file and drag their application to the Application folder.

A packaging tool can also help fill gaps left by other technologies such as Java Web Start, which was removed from Oracle���s JDK 11, and pack200, which was deprecated in JDK 11 for removal in a future release. Developers can use jlink to strip the JDK down to the minimal set of modules that are needed, and then use the packaging tool to produce a compressed, installable image that can be deployed to target machines.

To address these requirements previously, a packaging tool called javapackager was distributed with Oracle���s JDK 8. However, it was removed from Oracle���s JDK 11 as part of the removal of JavaFX.

Solution
--------
Create a new tool, jpackage, based on the JavaPackager delivered as part of JavaFX in JDK10.

The jpackage tool will take as input a Java application and a Java run-time image, and produce a Java application image that includes all the necessary dependencies. It will also be able to produce a native package in a platform-specific format, such as an exe on Windows or a dmg on macOS. The tool will have options that allow packaged applications to be customized in various ways.

In JDK 14 the tool and its SPI will be incubating.

### Features

The tool will provide the following features:

  - Creation of an application image

  - Support for native packaging formats to give the end user a more natural
    installation experience.
    Specifically, the tool will support the following formats:
    - Windows: `msi`, `exe`
    - macOS: `pkg`, `app` in a `dmg` (drag the app into the `Applications` directory)
    - Linux: `deb`, `rpm`

    Each format must be built on the platform it runs on, there is no cross-platform support.

    The application will be installed in the typical default directory for each platform
    unless the end-user specifies an alternate directory during the installation process 
    (for example, on Linux the default directory will be `/opt`).

  - The ability to specify JDK and application arguments at packaging time 
    that will be used when launching the application

  - The ability to package applications in ways that integrate into the native platform,
    for example:
    - Setting file associations to allow launching an application when a file with an 
      associated suffix is opened
    - Launching from a platform-specific menu group, such as Start menu items on Windows
    - Option to specify update rules for installable packages (such as in `rpm`/`deb`)
    - Ability to include desktop icons in platform-supported formats.

### Running the tool

The input to `jpackage` includes: a Java run-time image, a Java application in one of several formats, and various command line options to control the generation of the final image or package.

The following types of applications are supported:

  - Non-modular applications that run on the class path, and are in (one or more) `jar` files
  - Modular applications that are in (one or more) modular `jar` files or `jmod` files
  - Modular applications that have been `jlink`ed into a custom run-time image

If no custom run-time image is provided then the tool will run `jlink` to create a JDK for the application.

The output of `jpackage` is a self-contained Java application image. The image is stored in a single directory in the filesystem that can include the following:

  - Native application launcher (generated by the tool)
  - Application resources (e.g., `jar`, `icns`, `ico`, `png`)
  - Configuration files (e.g., `plist`, `cfg`, `properties`)
  - Helper libraries for the launcher
  - The Java run-time image 
    (including the application modules, if the app has been modularized)

### Sample usages

Generate an application package suitable for the host system:
```
    For a modular application:
        jpackage -n name -p modulePath -m moduleName/className
    For a non-modular application:
        jpackage -i inputDir -n name \
            --main-class className --main-jar myJar.jar
    From a pre-built application image:
        jpackage -n name --app-image appImageDir
```
Generate an application image:
```
    For a modular application:
        jpackage --type app-image -n name -p modulePath \
             -m moduleName/className
    For a non-modular application:
        jpackage --type app-image -i inputDir -n name \
            --main-class className --main-jar myJar.jar
```
To provide your own options to jlink, run jlink separately:
```
    jlink --output appRuntimeImage -p modulePath -m moduleName \
            --no-header-files [<additional jlink options>...]
    jpackage --type app-image -n name \
            -m moduleName/className --runtime-image appRuntimeImage
```
Generate a Java runtime package:
```
    jpackage -n name --runtime-image <runtime-image>
```


Specification
-------------
### API Documentation

src/jdk.incubator.jpackage/share/classes/module-info.java : 

```
    /**
     * Defines the Java Packaging tool, jpackage.
     *
     * <p>jpackage is a tool for generating self-contained application bundles.
     *
     * <p> This module provides the equivalent of command-line access to <em>jpackage</em>
     * via the {@link java.util.spi.ToolProvider ToolProvider} SPI.
     * Instances of the tool can be obtained by calling
     * {@link java.util.spi.ToolProvider#findFirst ToolProvider.findFirst}
     * or the {@link java.util.ServiceLoader service loader} with the name
     * {@code "jpackage"}.
     *
     * @implNote The {@code jpackage} tool is not thread-safe. An application
     * should not call either of the
     * {@link java.util.spi.ToolProvider ToolProvider} {@code run} methods
     * concurrently, even with separate {@code "jpackage"} {@code ToolProvider}
     * instances, or undefined behavior may result.
     *
     * @moduleGraph
     * @since 14
     */

    module jdk.incubator.jpackage {
    }

``` 
### Application Layout

The image format for an application named 'MyApp' will look like this on Windows:

```
  MyApp/
    MyApp.exe   [this is the native launcher]
    MyApp.ico
    app/
      [application configuration, and support files go here]
```
and will look like this on linux:
```
  MyApp/
    app/
      [application configuration, and support files go here]
    bin/
      MyApp   [this is the native launcher]
      MyApp.icns
```
and will look like this on macOs:

```
  MyApp.app/
    Contents/
      Info.plist
      app/
        [application configuration, and support files go here]
      MacOS/
        MyApp     [this is the native launcher]
      Resources/
        [application resource files go here]
```

Note that the helper libraries for the launcher and the Java run-time image used to run the application are not shown. The location and contents of these support files are implementation details that should not be relied upon or used directly by applications.

When the application is started, the launcher will read the configuration files and launch the embedded Java run-time image with the specified arguments.

The application image can be redistributed as-is, or it can be packaged as a native package (for example, in `msi` or `dmg` format).

In this latter case, the tool can either create a native package from a previously created application image, or it can create a native package directly. The native package will include the following:

  - The application image as defined above
  - Support for signing packages
  - Package post-processing steps such as setting up file associations

### Command line options

The `jpackage` usage is as follows:

```
jpackage <options>
```

Generic Options:

```
@<filename> ���
          Read options and/or mode from a file
          This option can be used multiple times.
--type -t <type> ---
          The type of package to create
          Valid values are: {"app-image", "exe", "msi", "rpm", "deb", "pkg", "dmg"}
          If this option is not specified a platform dependent
          default package type will be created.

--app-version <version> ���
          Version of the application and/or package

--copyright <copyright string> ���
          Copyright for the application

--description <description string> ���
          Description of the application

--help -h ���
          Print the usage text with a list and description of each valid
          option for the current platform to the output stream, and exit

--name -n <name> ���
          Name of the application and/or package

--dest -d <destination path> ���
          Path where generated output file is placed
          Defaults to the current working directory.
          (absolute path or relative to the current directory)

--temp <file path> ���
          Path of a new or empty directory used to create temporary files
          (absolute path or relative to the current directory)
          If specified, the temp dir will not be removed upon the task
          completion and must be removed manually
          If not specified, a temporary directory will be created and
          removed upon the task completion.

--vendor <vendor string> ���
          Vendor of the application

--verbose ���
          Enables verbose output

--version ���
          Print the product version to the output stream and exit
```

Options for creating the runtime image:

```
--add-modules <module name>[,<module name>...] ���
          A comma (",") separated list of modules to add.
          This module list, along with the main module (if specified)
          will be passed to jlink as the --add-module argument.
          if not specified, either just the main module (if --module is
          specified), or the default set of modules (if --main-jar is
          specified) are used.
          This option can be used multiple times.

--module-path -p <module path>... ���
          A ; separated list of paths
          Each path is either a directory of modules or the path to a
          modular jar.
          (each path is absolute or relative to the current directory)
          This option can be used multiple times.
 --bind-services ---
          Pass on --bind-services option to jlink (which will link in
          service provider modules and their dependences)
--runtime-image <file path> ���
          Path of the predefined runtime image that will be copied into
          the application image
          (absolute path or relative to the current directory).
          If --runtime-image is not specified, jpackage will run jlink to
          create the runtime image using options:
          --strip-debug, --no-header-files, --no-man-pages, and
          --strip-native-commands.

Options for creating the application image:

--icon <icon file path> ���
          Path of the icon of the application bundle
          (absolute path or relative to the current directory)

--input -i <input path> ���
          Path of the input directory that contains the files to be packaged
          (absolute path or relative to the current directory).
          All files in the input directory will be packaged into the
          application image.
```

Options for creating the application launcher(s):

```
--add-launcher <launcher name>=<file path> ---
          Name of launcher, and a path to a Properties file that contains
          a list of key, value pairs
          (absolute path or relative to the current directory)
          The keys "module", "add-modules", "main-jar", "main-class",
          "arguments", "java-options", "app-version", "icon", and
          "win-console" can be used.
          These options are added to, or used to overwrite, the original
          command line options to build an additional alternative launcher.
          The main application launcher will be built from the command line
          options. Additional alternative launchers can be built using
          this option, and this option can be used multiple times to
          build multiple additional launchers. 

--arguments <main class arguments> ���
          Command line arguments to pass to the main class if no command
          line arguments are given to the launcher
          This option can be used multiple times.

--java-options <java options> ���
          Options to pass to the Java runtime
          This option can be used multiple times.

--main-class <class name> ���
          Qualified name of the application main class to execute
          This option can only be used if --main-jar is specified.

--main-jar <main jar file> ���
          The main JAR of the application; containing the main class
          (specified as a path relative to the input path).
          Either --module or --main-jar option can be specified but not
          both.

--module -m <module name>[/<main class>] ���
          The main module (and optionally main class) of the application
          This module must be located on the module path.
          When this option is specified, the main module will be linked
          in the Java runtime image.  Either --module or --main-jar
          option can be specified but not both.
```

Platform dependent option for creating the application launcher:

```

Windows platform options (only available when running on Windows):

--win-console ���
          Creates a console launcher for the application, should be
          specified for application which requires console interactions

macOS platform options (only available when running on macOS): 

--mac-package-identifier <ID string> ���
          An identifier that uniquely identifies the application for macOS.
          Defaults to the main class name.
          May only use alphanumeric (A-Z,a-z,0-9), hyphen (-),
          and period (.) characters.

--mac-package-name <name string> ���
          Name of the application as it appears in the Menu Bar
          This can be different from the application name.
          This name must be less than 16 characters long and be suitable for
          displaying in the menu bar and the application Info window.
          Defaults to the application name.

--mac-package-signing-prefix <prefix string> ���
          When signing the application bundle, this value is prefixed to all
          components that need to be signed that don't have
          an existing bundle identifier.

--mac-sign ���
          Request that the bundle be signed

--mac-signing-keychain <file path> ���
          Path of the keychain to use
          (absolute path or relative to the current directory).
          If not specified, the standard keychains are used.

--mac-signing-key-user-name <user name> ���
          User name portion of the typical
          "Mac Developer ID Application: <user name>" signing key
```

Options for creating the application package:

```
--app-image <file path> ���
          Location of the predefined application image that is used
          to build an installable package
          (absolute path or relative to the current directory).

--file-associations <file path> ���
          Path to a Properties file that contains list of key, value pairs
          (absolute path or relative to the current directory).
          The keys "extension", "mime-type", "icon", and "description"
          can be used to describe the association.
          This option can be used multiple times.

--install-dir <file path> ���
          Absolute path of the installation directory of the application on OS X
          or Linux. Relative sub-path of the installation location of the application
          such as "Program Files" or "AppData" on Windows.

--license-file <file path> ���
          Path to the license file
          (absolute path or relative to the current directory)

--resource-dir <path> ���
          Path to override jpackage resources.
          Icons, template files, and other resources of jpackage can be
          over-ridden by adding replacement resources to this directory.
          (absolute path or relative to the current directory)

--runtime-image <file-path> ���
          Path of the predefined runtime image to install
          (absolute path or relative to the current directory).
          Option is required when creating a runtime package.
```

Platform dependent options for creating the application package:

```

Windows platform options (only available when running on Windows): 

--win-dir-chooser ���
          Adds a dialog to enable the user to choose a directory in which
          the product is installed

--win-menu ���
          Adds the application to the system menu

--win-menu-group <menu group name> ���
          Start Menu group this application is placed in

--win-per-user-install ���
          Request to perform an install on a per-user basis

--win-shortcut ���
          Creates a desktop shortcut for the application

--win-upgrade-uuid <id string> ���
          UUID associated with upgrades for this package

Linux platform options (only available when running on Linux):

--linux-shortcut ���
          Creates a shortcut for the application

--linux-package-name <bundle name> ���
          Name for Linux bundle, defaults to the application name

--linux-deb-maintainer <email address> ���
          Maintainer for .deb bundle

--linux-menu-group <menu-group-name> ���
          Menu group this application is placed in

--linux-package-deps ���
          Required packages or capabilities for the application

--linux-rpm-license-type <type string> ���
          Type of the license ("License: <value>" of the RPM .spec)

--linux-app-category <category value> --
          Group value of the RPM <name>.spec file or Section value of DEB control file.

```

### Additional Notes

    --java-options <java options>
          The string of java options can contain the $APPDIR variable to refer to the location within the
          app-image where files taken from the input directory (specified by --input option) are.  When a
          program is launched, any instances of the string "$APPDIR" in the java options will be expanded
          to point to the location of the app dir within the application image.

    --app-image <app image dir>
          An app-image is a directory  that can be the output of a previous
          invocation of jpackage specifying --package-type "app-image".  An app image
          directory  can alternatively contain anything you want bundled as the application,
          It must contain at least the executable application .

    --add-launcher <name>=<additional launcher properties file path>
         An application image will contain at least one main application launcher,
         defined by the options passed to jpackage.
         It may also create one or several additional launchers defined by this
         option.  The additional launcher with the name <name> is defined by the
         combination of those options and the properties in given properties file.
         The <name> given must be a valid filename different than the name of 
         the main application, or any other previous additional launcher.
         "name", and it's value cannot be the same as the main app.
         A secondary launcher properties file may optionally have any of 
         the following properties:
          * app-version
          * module
          * main-jar
          * main-class
          * icon
          * arguments
          * java-options
          * win-console
          * linux-app-category
        Using the same input files as the main launcher, jpackage will then create a
        additional launcher with the given name using the combined options.

    -- when an option value is a string:
        If a string value contains space characters, the argument must be quoted, 
        else the shell will consider each word a separate argument.

    -- when option value is a list:
        If an option value is a list of file paths, each element in the list must be
        separated by File.pathSeparator. The above help output was generated on 
        windows platform, so help text says "A ; separated list of file ..." If run on 
        linux or Mac, the help output would be "A : separated list of file ...".
        If an option value is a list of module names then they must be separated by
        a comma.
        If an option value is otherwise a list of strings, they must separated by 
        space characters.  Since the shell would otherwise take them as separate 
        arguments, the list must be quoted.
        If a list of strings contains a string which contains space characters, quote 
        the string and list of strings with different quote characters such as:
        --java-options "-ea '-Dmy.tmp.path=\Program Files\temp'"

    --  Specifying an option multiple times.
        The following options can be specified multiple times in one command:
          * --java-options
          * --arguments
          * --module-path
          * --add-modules
          * --file-associations
          * --add-launcher
         If any of the above options are given multiple times, the value used will
         be the  combination of the given values (as described below).
         If any other option is given multiple times, only the last value will be used.

    -- Options whose value is a list can optionally be specified multiple times,
        so that :
        --java-options "-server -ea -Dfoo=bar"
        is the same as
        --java-options -server --java-options "--ea -Dfoo=bar"
        or
        --java-options -server --java-options -ea --java-options -Dfoo=bar

        The options --java-options, --arguments,  --module-path, and --add-modules
        are lists that can either be specified in one option or by multiple options.

        The options --file-associations and --add-launcher are file paths, so to
        create multiple associations or additional launchers, multiple options 
        must be used as:
        "--file-associations assoc1.properties --file-associations assco2.properties", or
        "--add-launcher launcher2.properties --add-launcher launcher3.properties".

  --


Comments
Moving amended request to Approved.
05-12-2019

I updated both this CSR and the man page to contain "Each format must be built on the platform it runs on, there is no cross-platform support.". I also updated both man pages and CSR when saying Windows platform options: to add the clause as follows: Windows platform options (only available when running on WIndows): and similar for Linux and macOS, so it should be clear that the platform specific options can only be issued on the platform in question.
05-12-2019

> Please explicitly indicate in the man page & spec that "cross compilation" is not supported; > that is the platform specific options can only be issued on the platform in question. Is part of the confusion that there are references to the platform specific options ? If man pages were per-platform they would only list the options related to their platform, so it is not ideal at all to have them all together. So perhaps the man page could say "Options for all platforms are documented here, but only options for the current platform can be used. Each bundle must be built on the target platform". Why does the spec need to say this rather than just the solution section ?
05-12-2019

> If the supported formats for icons are whatever is supported by the target platform, >please change the text to indicate this. (Historically, IIRC there were some issues around what > format the launcher supported for splashscreen files.) I think this is done : > Ability to include desktop icons in platform-supported formats. It is not the same as the splashscreen case. There Java is interpreting the files. Here we are talking about icon files that only the platform installer and desktop read.
05-12-2019

If the supported formats for icons are whatever is supported by the target platform, please change the text to indicate this. (Historically, IIRC there were some issues around what format the launcher supported for splashscreen files.) Thank you for attaching the man page. Please explicitly indicate in the man page & spec that "cross compilation" is not supported; that is the platform specific options can only be issued on the platform in question. Marked the request as pended until these issues are addressed or commented upon; please re-finalized when ready.
05-12-2019

> What file types are supported for icons? This is just "whatever is supported by the target platform", so jpackage doesn't specify this. > Is there a draft "man page" in addition to the discussion in the specification section above? If so, it should be attached to the CSR. There's a draft but it is not up to date, so it is better not to until the docs team have updated it. Everything that would be there is in the CSR anyway > I'm assuming this tool does not support cross platform package generation (e.g. generating a windows package on a linux system). This should be made more explicit in the specification section. It is in the JEP as a non-goal, but I am not sure why we need to specify the things we don't do in the CSR ..
04-12-2019

Moving to Provisional. What file types are supported for icons? Is there a draft "man page" in addition to the discussion in the specification section above? If so, it should be attached to the CSR. I'm assuming this tool does *not* support cross platform package generation (e.g. generating a windows package on a linux system). This should be made more explicit in the specification section.
04-12-2019

The updated version looks good to me and matches the latest version of the tool, which is now Proposed to Target JDK 14.
19-11-2019

Moving to Approved.
13-05-2019

Moving to Provisional.
24-04-2019

In the latest version SingleInstanceService was removed, so there is now no API associated with jpackage. the above was resolved by having --version and -v print the version as done by other tools, and using --appVersion to specify an applications version.
09-01-2019

We have --version argument for jpackager itself which will show jpackager version. jpackager.exe --version jpackager version 12-internal CSR only mentions about --version to set application version. We should probably mention about second usage of --version. Do we need support -v to show jpackager version?
17-11-2018

Various comments on the current draft: Please clarify that the tool can only create a bundle for the host platform... --files -f <input files> A ; separated list of files in the input directory to be packaged. Should a ":" be used as a separator on windows? What happen if a subdirectory is specified as an input? What kind of file formats are supported for --icon <icon file name> Icon of the application bundle For --jvm-args <java vm arguments> JVM flags and options to pass to the application. how are multiple JVM arguments passed? Quoted as in --jvm-arg "-server --foo bar" or --jvm-arg '-server --foo bar' or with multiple --jvm-arg inputs, --jvm-arg -server --jvm-arg " --foo bar" For all the names taken as arguments, are there encoding issues to worry about? Are there any interactions with multi-release jar files or signed jar files (or signed multi-release jar files, etc.) that need to be accounted for in the command line options? Moving to Provisional, but will want to see these issues addressed before the CSR is finalized.
15-11-2018

I have updated the content to address the above questions, and am moving to Propose state
10-11-2018

Before the request is finalized, I think the set of examples would be improved if there were some module-based ones included. Operationally, what does "create-jre-installer" mean, same as create-installer but uses with an implicit --limit-modules argument? What is the secondary-launcher? Moving to Provisional, but I think some refinements will be needed before the request is ready to be finalized.
09-11-2018

> jpackager uses jdk.tools.jlink.internal.packager.AppRuntimeImageBuilder to create the application image that is bundled. You can also use jlink to create the runtime used as a --runtime-image arg. > > A packaged application is the same as any other java application wrt AppCDS. > > jpackager makes no direct usage of AOT > > Correct, as stated in the JEP under non-goals: > "There will be no support for cross compilation. For example, in order to create Windows packages one must run the tool on Windows. The tool can depend upon platform-specific tools." > > Although we no longer distribute a JRE or a Server-JRE, jpackager can be used to generate a custom JRE from a standard or custom JDK. Perhaps it would be better to use a different term than "JRE". Do you have any suggestions ?
07-11-2018

How does this tool interact with jlink and AOT/AppCDS? Is it correct that the tool cannot create packaging artifact for other platforms? In other words, cannot create a MacOS DMG file running on Linux? There isn't currently a separate JRE download so it is odd it see that term used in the command syntax.
06-11-2018