Java 16 JPackage パッケージの実行可能ファイル exe

ブログ投稿ディレクトリ


Maven プロジェクトの構造

ここに画像の説明を挿入

JDK17

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mrathena</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1</version>

    <dependencies>
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>3.0</version>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

</project>

com.mrathena.gui

package com.mrathena;

import com.formdev.flatlaf.FlatDarkLaf;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Objects;

public class Gui {
    
    
    private JPanel root;
    public static void main(String[] args) {
    
    
        FlatDarkLaf.setup();
        JFrame frame = new JFrame("Gui");
        ImageIcon icon = new ImageIcon(Objects.requireNonNull(Gui.class.getClassLoader().getResource("icon.png")));
        frame.setIconImage(icon.getImage());
        frame.setContentPane(new Gui().root);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 450);
        frame.setLocationRelativeTo(null); // 居中
        frame.setVisible(true);
    }
}

パッケージングジャー(アイデアは機能に付属しています)

demo.jar、サイズ 862KB、正常に実行java -jar demo.jarできること、フォームを開く

ここに画像の説明を挿入

Java 16 Jパッケージ

jpackage -h
C:\mrathena\develop\workspace\idea\demo\out\artifacts\demo_jar>jpackage -h
Usage: jpackage <options>

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 \
                --add-modules 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>

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"}
          If this option is not specified a platform dependent
          default 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
  --icon <file path>
          Path of the icon of the application package
          (absolute path or relative to the current directory)
  --name -n <name>
          Name of the application and/or package
  --dest -d <destination path>
          Path where generated output file is placed
          (absolute path or relative to the current directory)
          Defaults to the current working directory.
  --temp <directory 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.
  --jlink-options <jlink options>
          A space separated list of options to pass to jlink
          If not specified, defaults to "--strip-native-commands
          --strip-debug --no-man-pages --no-header-files".
          This option can be used multiple times.
  --runtime-image <directory 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:
  --input -i <directory 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", "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.

用来创建应用程序启动程序的与平台相关的选项:
  --win-console
          为应用程序创建控制台启动程序,应当为
          需要控制台交互的应用程序指定

Options for creating the application package:
  --about-url <url>
          URL of the application's home page
  --app-image <directory 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 <directory path>
          默认安装位置下面的相对子路径
  --license-file <file path>
          Path to the license file
          (absolute path or relative to the current directory)
  --resource-dir <directory 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 <directory 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:
  --win-dir-chooser
          Adds a dialog to enable the user to choose a directory in which
          the product is installed.
  --win-help-url <url>
          URL where user can obtain further information or technical support
  --win-menu
          Request to add a Start menu shortcut for this application
  --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
          Request to add desktop shortcut for this application
  --win-shortcut-prompt
          Adds a dialog to enable the user to choose if shortcuts
          will be created by installer.
  --win-update-url <url>
          URL of available application update information
  --win-upgrade-uuid <id string>
          UUID associated with upgrades for this package

いくつかのパラメータの説明

jpackage - 自己完結型 Java アプリケーションをパッケージ化するためのツール. オラクルの公式ドキュメントによる翻訳

パラメータ 例証する
アプリケーションパッケージ プログラムを直接実行する代わりにプログラムをインストールする
アプリケーションイメージ プログラムを実行すると、実際にはインストールが完了した後にインストーラーによって生成されるコンテンツです
- -
--input -i <directory path> パッケージング ディレクトリを指定します。このディレクトリ内のすべてのコンテンツがパッケージ化されます。相対パスを使用して、他のパラメータでこのディレクトリ内のファイルを参照できます。パッケージ化する前に、jar/ioc およびその他のファイルをこのディレクトリにコピーできます。
--dest -d <destination path> 生成された製品の出力パス。デフォルト値は現在の cmd の作業パスです。タイプで app-image が選択されている場合、出力パスを –input で指定されたディレクトリと同じパスにすることはできないことに注意してください。 –dest を指定した場合、出力パスは表示されません.これは現在のパス、つまり –input で指定されたパスであり、–input で指定されたディレクトリ内のすべてのコンテンツがパッケージ化されます.この場合、生成プログラムは無限ループに陥り、無限にネストされたフォルダーが生成され、削除できません
--name -n <name> アプリケーション名
--type -t <type> 生成するパッケージのタイプ。オプションの値は {"app-image", "exe", "msi"} です。exe と msi はどちらもインストール パッケージで、app-image は直接実行できるプログラムです。
--app-version <version> アプリケーションのバージョン番号は、1.0、1.3.2、同様の形式である必要があります。値は [0-255] の範囲で、任意の文字列を指定することはできません
--icon <file path> 生成されたパッケージのアイコン。インストーラが生成された場合、インストーラ自体がこのアイコンを使用します。インストール後の実行可能 exe は、このアイコンを使用しません。生成された実行可能ファイルが直接の場合、実行可能ファイルはこのアイコンを使用します。
--vendor <vendor string> アプリの作者
--copyright <copyright string> アプリの著作権
--description <description string> アプリケーションの説明
``
``

WIX v3

ここに画像の説明を挿入

使用するにはjpackage、 WIX v3 以降、公式サイトGitHubをインストールする必要があります。

インストール後、環境変数を設定せずにそのまま使えるようです

パック

  • モジュラー Java プロジェクト (非 Maven / Gradle) パッケージング
  • モジュラー Java Maven プロジェクトのパッケージ化
  • 非モジュラー Java プロジェクトのパッケージ化

以下の記事内容を参照

Windows Java JavaFX IntelliJ IDEA 開発環境のセットアップ プロジェクトの作成 コンパイルと実行 パッケージとカスタム ランタイムの配布

おすすめ

転載: blog.csdn.net/mrathena/article/details/129838350