在 Windows 上使用 JPackage 是否可以使 main .exe 不作为控制台运行,但让其他启动程序作为控制台运行?

Pau*_*lor 5 java java-14 jpackage

使用 JPackage,我无法获得 --win-console 选项来为主启动器单独工作,但我希望主启动器不输出到控制台,但有一个可以输出到控制台的调试版本。

即如果我跑

jpackage --add-launcher SongKongDebug=jpackage.properties @jpackage.txt 
Run Code Online (Sandbox Code Playgroud)

jpackage.txt

-i C:\Code\jthink\SongKong\target\songkong-6.10
--runtime-image C:\code\jthink\songkong\JVM64
--main-class com.jthink.songkong.cmdline.SongKong
--name SongKong
--win-dir-chooser
--main-jar lib\SongKong-6.10.jar
--app-version 6.10
--install-dir Jthink\SongKong
--copyright "Copyright 2020 JThink Ltd, United Kingdom"
--license-file C:\Code\jthink\SongKong\src\main\scripts\license.txt
--java-options "-Dhttps.protocols=TLSv1.1,TLSv1.2"
--java-options "--add-opens java.base/java.lang=ALL-UNNAMED"
--java-options "-XX:MaxRAMPercentage=75.0"
--java-options "-XX:MetaspaceSize=45 "
--java-options "-Dcom.mchange.v2.log.MLog=com.mchange.v2.log.jdk14logging.Jdk14MLog"
--java-options "-Dorg.jboss.logging.provider=jdk"
--java-options "-Djava.util.logging.config.class=com.jthink.songkong.logging.StandardLogging"
--vendor JThink
--win-menu
--win-shortcut
--win-menu-group Jthink
Run Code Online (Sandbox Code Playgroud)

jpackage.properties

win-console=--win-console
Run Code Online (Sandbox Code Playgroud)

然后 SongKong 和 SongKongDebug 都在没有控制台的情况下运行

我还尝试修改 jpackage.properties (这意味着名称/值对)以

--win-console
Run Code Online (Sandbox Code Playgroud)

但还是没用

而如果我添加

--win-console 
Run Code Online (Sandbox Code Playgroud)

到 jpackage.txt 和

win-console 
Run Code Online (Sandbox Code Playgroud)

到 jpackage.properties

那么SongKong将作为控制台运行,而SongKongDebug不会,但对我来说是错误的。

如果我将SongKong重命名为SongKongDebug,将SongKongDebug 重命名SongKong

例如

jpackage --add-launcher SongKong=jpackage.properties @jpackage.txt
Run Code Online (Sandbox Code Playgroud)

并修改 set --name SongKongDebug

在jpackage.txt中

然后它可以工作,但现在安装 SongKong 时它说安装SongKongDebug这是错误的。

我已经尝试过当前的 Java 14 版本和早期访问 Java 15 和 16 版本,但没有什么区别。

我发现报告了这个错误,但随后用户将其关闭,没有问题https://bugs.openjdk.java.net/browse/JDK-8213717,我发现 jpackage 帮助有点令人困惑,所以我想知道我是否做错了方式。

帮助说

创建应用程序启动器的选项:

--add-launcher 启动器名称=文件路径

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
Run Code Online (Sandbox Code Playgroud)

目录)。

The keys "module", "add-modules", "main-jar", "main-class", "arguments", "java-options", "app-version", "icon", and "win-console"
Run Code Online (Sandbox Code Playgroud)

可以使用。

These options are added to, or used to overwrite, the original command line options to build an additional alternative launcher. The
Run Code Online (Sandbox Code Playgroud)

主应用程序启动器将从命令行选项构建。可以使用此选项构建其他替代启动器,并且可以多次使用此选项来构建多个附加启动器。--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.
Run Code Online (Sandbox Code Playgroud)

--java-options java 选项

Options to pass to the Java runtime.

This option can be used multiple times.
Run Code Online (Sandbox Code Playgroud)

--主类类名

Qualified name of the application main class to execute.

This option can only be used if --main-jar is specified.
Run Code Online (Sandbox Code Playgroud)

--main-jar 主 jar 文件

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.
Run Code Online (Sandbox Code Playgroud)

--module 或 -m 模块名称/主类]

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
Run Code Online (Sandbox Code Playgroud)

指定但不是两者都指定。

因此,您可以使用 --add-launcher 创建附加启动器并使用属性文件,但这也使得听起来您可以将额外的参数作为附加命令行选项传递,但这怎么可能,因为不清楚哪个启动器他们指的是?

Dun*_*ncG 3

您可以使用或为每个--add-launcher属性文件 指定控制台选择:win-console=truewin-console=false

jpackage.properties

 # This adds console for the current launcher:
 win-console=true
Run Code Online (Sandbox Code Playgroud)

在命令行或参数@jpackage.txt文件中,主应用程序和所有未指定的文件--win-console在控制台上切换标志:--add-launcherwin-console=true|false

@jpackage.txt

# This adds console for all applications:
--win-console
Run Code Online (Sandbox Code Playgroud)

不幸的是,jpackage 有错误JDK-8253426,它阻止--add-launcher设置main-class=xyz在 JDK15 中使用不同的设置。