简体   繁体   English

jPackage - Wix - 应用程序无法启动,但没有诊断消息

[英]jPackage - Wix - App doesn’t launch, but there are no diagnostic messages

I have been trying to package my java javafx desktop application using jPackage on Windows.我一直在尝试 package 我的 java javafx 桌面应用程序在 ZAEA234298CE3AA9B448B33D21F46Z javafx 桌面应用程序上使用 jPackage

The application runs fine under Netbeans but nothing happens (no error messages) when I click the shortcut produced by the installer or by trying to run it using the command line interface.该应用程序在 Netbeans 下运行良好,但是当我单击安装程序生成的快捷方式或尝试使用命令行界面运行它时,没有任何反应(没有错误消息)。

I am using java version 17.0.1 2021-10-19 LTS我正在使用 java 版本 17.0.1 2021-10-19 LTS

Questions问题

I have been unable to discover what the error is.我一直无法发现错误是什么。 It runs quite happily in Netbeans, so I am thinking it is something with the way I have set up JPackage arguments but I can't see what the error is.它在 Netbeans 中运行得非常愉快,所以我认为这与我设置 JPackage arguments 的方式有关,但我看不出错误是什么。 Without any diagnostic messages it is difficult to diagnose the problem.如果没有任何诊断消息,就很难诊断问题。

  1. How can I see any messages when the app fails to launch?应用程序启动失败时如何查看任何消息?
  2. I am using the JavaFX modules.我正在使用 JavaFX 模块。 Should I include the javafx jar files in my class path libs folder?我应该在我的 class 路径库文件夹中包含 javafx jar 文件吗? I am guessing I shouldn't as I am including the modules.我猜我不应该因为我包含模块。
  3. Should I try and run it from the console by creating a console launcher.我是否应该通过创建控制台启动器来尝试从控制台运行它。 I don't know how yet but will investigate.我还不知道怎么做,但会调查。 I may be able to see diagnostic error and system out messages.我可能会看到诊断错误和系统输出消息。
  4. Does the app launcher display any diagnostic messages that may help to diagnose the problem.应用启动器是否显示任何可能有助于诊断问题的诊断消息。

What did I do to create the App Installer我做了什么来创建应用程序安装程序

Before running JPackage, I created a "Package" directory and copied the main jar file and other application files to a "config" directory within it.在运行 JPackage 之前,我创建了一个“Package”目录并将 jar 主文件和其他应用程序文件复制到其中的“config”目录中。 I then defined the config directory as the input directory.然后我将配置目录定义为输入目录。 The output directory to my current directory. output 目录到我的当前目录。 (see jPackage command below). (参见下面的 jPackage 命令)。

My packaging directory structure is therefore...因此,我的打包目录结构是...

jPackage目录结构

The config file contains the following:配置文件包含以下内容:

在此处输入图像描述

The libs folder contains a list of jars such as log4j etc and under the mods folder is the javaFX 17 modules. libs 文件夹包含 jars 列表,例如 log4j 等,mods 文件夹下是 javaFX 17 个模块。

PictureTool4-1.0.exe is the installer generated by JPackage with the following command: PictureTool4-1.0.exe是JPackage生成的安装程序,命令如下:

c:\Dev\Package\PictureTool4\Package>jPackage --name pictureTool4 --input config  --main-jar PictureTool4-4-0.jar  --module-path mods\javafx-jmods-17.0.1 --add-modules javafx.media,javafx.fxml,javafx.swing,javafx.controls,javafx.graphics --win-dir-chooser --win-shortcut

The Manifest file in the PictureTool4-4-0.jar contains the main class: PictureTool4-4-0.jar中的Manifest文件包含主要的class:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.6.3
Built-By: User
Build-Jdk: 17.0.1
Class-Path: libs/log4j-api-2.13.0.jar etc ... list of jars)
Main-Class: omac.main.JFXPictureToolMain

What else have I tried… *我还尝试了什么…… *

1 Added a system out message. 1 添加了系统退出消息。

Straight after the applications main...紧接着应用程序主...

    public static void main(String[] args) {
            System.out.println("PictureTool4 has started");
    launch(args);
}
  1. Added a splash screen添加了启动画面

And added a splash screen by adding --java-options "-splash:\$APPDIR/PictureTool-Splash.jpg" to the jPackage arguments.并通过将--java-options "-splash:\$APPDIR/PictureTool-Splash.jpg"添加到 jPackage arguments 来添加启动屏幕。

The application didn't display a splash screen or any messages.该应用程序没有显示启动画面或任何消息。

References参考

Stackoverflow.com In Java how do you debug exe created by JPackage Stackoverflow.com 在 Java 你如何调试 JPackage 创建的 exe

https://docs.oracle.com/en/java/javase/14/jpackage/packaging-tool-user-guide.pdf https://docs.oracle.com/en/java/javase/14/jpackage/packaging-tool-user-guide.pdf

Your command line does not mention --win-console as referenced in the other SO post so ensure that is active first.您的命令行未提及其他 SO 帖子中引用的--win-console ,因此请确保首先处于活动状态。

Then check that you have not fallen to this trap - second installer never runs if you have same app version .然后检查您是否已陷入此陷阱 - 如果您的应用程序版本相同,则第二个安装程序永远不会运行

Once done above and re-built, properly uninstall the last installed version and re-install using the new jpackage installer.完成上述操作并重新构建后,正确卸载最后安装的版本并使用新的jpackage安装程序重新安装。

If the EXE still doesn't work, double check you have the required application dependencies and test the Java runtime that the implicit jlink made by jpackage has built for you actually contains the dependencies.如果 EXE 仍然不起作用,请仔细检查您是否具有所需的应用程序依赖项并测试jpackage为您构建的隐式jlink实际包含依赖项的 Java 运行时。 This is simple from the command line, just run your Java app with the new JRE HOME:这从命令行很简单,只需使用新的 JRE HOME 运行 Java 应用程序:

set "APP_HOME=C:\Program Files\YOUR_APP"
%JAVA_HOME%\runtime\bin\java -cp %APP_HOME%\app\PictureTool4-4-0.jar your.Main

If above does not work, you have missed off libraries.如果上述方法不起作用,则您错过了库。 Consider using jlink explicitly ( as in this answer ) because if your app jar module dependencies don't change, you don't need to re-generate the JRE using the implicit jlink made by jpackage .考虑显式使用 jlink( 如本答案所示),因为如果您的应用程序 jar 模块依赖项没有更改,则无需使用jpackage制作的隐式jlink重新生成 JRE。

How can I convert my Java program to an.exe file? 如何将我的 Java 程序转换为 an.exe 文件?

I have now resolved my packaging issues and the app is now running.我现在已经解决了我的打包问题,应用程序现在正在运行。 I decided, I would post my solution here and not as an update to my question.我决定,我会在这里发布我的解决方案,而不是作为我的问题的更新。

I did the packaging in three steps:我分三步完成了包装:

  1. Changed the app to look in the app directory for its properties file.将应用程序更改为在应用程序目录中查找其属性文件。
  2. Determined my apps java module dependencies.确定了我的应用程序 java 模块依赖项。
  3. Used the list of modules, my app's jar, and public jars my app uses, to build my apps windows installer.使用模块列表、我的应用程序的 jar 和我的应用程序使用的公共 jars 来构建我的应用程序 windows 安装程序。

Step 1 My app looked in the root directory for a properties file.第 1 步我的应用程序在根目录中查找属性文件。 However the app installer produced by jPackage creates a runTime and an app directory.然而,由 jPackage 生成的应用安装程序会创建一个运行时和一个应用目录。 The root directory only contains an app exe file and an ico file.根目录只包含一个app exe文件和一个ico文件。 jPackage copies all the files in the directory defined in the -input argument to the app directory including my properties file. jPackage 将 -input 参数中定义的目录中的所有文件复制到应用程序目录,包括我的属性文件。 I therefore changed my app to look in the apps directory rather than the root.因此,我将我的应用程序更改为查看应用程序目录而不是根目录。

Step 2 - To determine what java modules my app needed I used jdeps with my apps jar file, javaFX jars (not modules) and the public jars my app uses, to produce a list of packages my app needs. Step 2 - To determine what java modules my app needed I used jdeps with my apps jar file, javaFX jars (not modules) and the public jars my app uses, to produce a list of packages my app needs. This was not a very user friendly list, but I was able to manually create the list of java modules I needed.这不是一个非常用户友好的列表,但我能够手动创建我需要的 java 模块的列表。

When I ran jdeps I got the error "Module java.activation not found, required by java.xml.bind".当我运行 jdeps 时,出现错误“未找到模块 java.xml.bind 所需的模块 java.activation。” As follows:如下:

    C:\Dev\Package\PictureTool4\Package>jdeps  -summary  --multi-release 17 config/PictureTool4-4.0.jar config/libs/apiguardian-api-1.1.0.jar config/libs/commons-csv-1.4.jar config/libs/javassist-3.28.0-GA.jar config/libs/javax.activation-api-1.2.0.jar config/libs/log4j-api-2.13.0.jar config/libs/log4j-core-2.13.0.jar config/libs/jaxb-api-2.3.1.jar config/libs/jaxb-core-2.3.0.1.jar config/libs/jaxb-impl-2.3.1.jar jfxlib/javafx.controls.jar jfxlib/javafx.controls.jar jfxlib/javafx.fxml.jar jfxlib/javafx.swing.jar jfxlib/javafx.base.jar jfxlib/javafx.graphics.jar
Exception in thread "main" java.lang.module.FindException: Module java.activation not found, required by java.xml.bind
        at java.base/java.lang.module.Resolver.findFail(Resolver.java:893)
        at java.base/java.lang.module.Resolver.resolve(Resolver.java:192)
        at java.base/java.lang.module.Resolver.resolve(Resolver.java:141)
        at java.base/java.lang.module.Configuration.resolve(Configuration.java:421)
        at java.base/java.lang.module.Configuration.resolve(Configuration.java:255)
        at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
        at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
        at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
        at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
        at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)

I assumed that jaxb was causing the issue so I removed the jars from the list.我假设 jaxb 导致了这个问题,所以我从列表中删除了 jars。 I don't know why jDeps complained, but I am guessing its because jaxb 2.3.1 is not compatible with Java SE 17. I will do some further research.我不知道为什么 jDeps 抱怨,但我猜是因为 jaxb 2.3.1 与 Java SE 17 不兼容。我会做一些进一步的研究。 When I ran jDeps again it gave me a list of packages as follows:当我再次运行 jDeps 时,它给了我一个包列表,如下所示:

`C:\Dev\Package\PictureTool4\Package>jdeps  -summary --multi-release 17 config/PictureTool4-4.0.jar config/libs/apiguardian-api-1.1.0.jar config/libs/commons-csv-1.4.jar config/libs/javassist-3.28.0-GA.jar config/libs/javax.activation-api-1.2.0.jar config/libs/log4j-api-2.13.0.jar config/libs/log4j-core-2.13.0.jar jfxlib/javafx.controls.jar jfxlib/javafx.fxml.jar jfxlib/javafx.swing.jar jfxlib/javafx.base.jar jfxlib/javafx.graphics.jar
    PictureTool4-4.0.jar -> config\libs\commons-csv-1.4.jar
    PictureTool4-4.0.jar -> java.base
    PictureTool4-4.0.jar -> java.datatransfer
    PictureTool4-4.0.jar -> java.desktop
    PictureTool4-4.0.jar -> java.logging
    PictureTool4-4.0.jar -> java.prefs
    PictureTool4-4.0.jar -> java.xml
    PictureTool4-4.0.jar -> javafx.base
    PictureTool4-4.0.jar -> javafx.controls
    PictureTool4-4.0.jar -> javafx.fxml
    PictureTool4-4.0.jar -> javafx.graphics
    PictureTool4-4.0.jar -> javafx.swing
    PictureTool4-4.0.jar -> not found
    PictureTool4-4.0.jar -> org.apache.logging.log4j
    commons-csv-1.4.jar -> java.base
    commons-csv-1.4.jar -> java.sql
    javafx.base -> java.base
    javafx.base -> java.desktop
    javafx.base -> jdk.jfr
    javafx.controls -> java.base
    javafx.controls -> javafx.base
    javafx.controls -> javafx.graphics
    javafx.fxml -> java.base
    javafx.fxml -> java.scripting
    javafx.fxml -> java.xml
    javafx.fxml -> javafx.base
    javafx.fxml -> javafx.graphics
    javafx.graphics -> java.base
    javafx.graphics -> java.desktop
    javafx.graphics -> java.xml
    javafx.graphics -> javafx.base
    javafx.graphics -> jdk.unsupported
    javafx.swing -> java.base
    javafx.swing -> java.datatransfer
    javafx.swing -> java.desktop
    javafx.swing -> javafx.base
    javafx.swing -> javafx.graphics
    javafx.swing -> jdk.unsupported.desktop
    javassist-3.28.0-GA.jar -> java.base
    javassist-3.28.0-GA.jar -> java.desktop
    javassist-3.28.0-GA.jar -> java.instrument
    javassist-3.28.0-GA.jar -> java.management
    javassist-3.28.0-GA.jar -> jdk.attach
    javassist-3.28.0-GA.jar -> jdk.jdi
    javax.activation-api-1.2.0.jar -> java.base
    javax.activation-api-1.2.0.jar -> java.datatransfer
    javax.activation-api-1.2.0.jar -> not found
    log4j-core-2.13.0.jar -> config\libs\commons-csv-1.4.jar
    log4j-core-2.13.0.jar -> java.base
    log4j-core-2.13.0.jar -> java.compiler
    log4j-core-2.13.0.jar -> java.desktop
    log4j-core-2.13.0.jar -> java.logging
    log4j-core-2.13.0.jar -> java.management
    log4j-core-2.13.0.jar -> java.naming
    ...etc
`

Jdeps identified 21 modules I needed to include in the apps Runtime. Jdeps 确定了我需要包含在应用程序运行时中的 21 个模块。

Step 3 - Packaging.第 3 步- 包装。 I used the 21 dependencies identified in step 2 and built the installer using jPackage as follows:我使用了步骤 2 中确定的 21 个依赖项,并使用 jPackage 构建了安装程序,如下所示:

jPackage --name PictureTool4 --input config  --main-jar PictureTool4-4.0.jar --win-dir-chooser --win-shortcut --module-path mods\javafx-jmods-17.0.1 --add-modules javafx.media,javafx.fxml,javafx.swing,javafx.controls,javafx.graphics,java.datatransfer,java.desktop,java.logging,java.prefs,java.xml,java.sql,java.scripting,jdk.unsupported.desktop,java.instrument,java.management,jdk.attach,jdk.jdi,java.compiler,java.naming,java.rmi

I then installed the app and it worked as expected.然后我安装了该应用程序,它按预期工作。

I am new to Stack Overflow, so thankyou for your help.我是 Stack Overflow 的新手,非常感谢您的帮助。

Directory Structure目录结构

目录结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM