简体   繁体   中英

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.

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.

I am using java version 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. 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. Should I include the javafx jar files in my class path libs folder? 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. I then defined the config directory as the input directory. The output directory to my current directory. (see jPackage command below).

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.

PictureTool4-1.0.exe is the installer generated by JPackage with the following command:

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:

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.

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.

The application didn't display a splash screen or any messages.

References

Stackoverflow.com In Java how do you debug exe created by JPackage

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.

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.

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. This is simple from the command line, just run your Java app with the new JRE HOME:

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 .

How can I convert my Java program to an.exe file?

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.
  3. Used the list of modules, my app's jar, and public jars my app uses, to build my apps windows installer.

Step 1 My app looked in the root directory for a properties file. However the app installer produced by jPackage creates a runTime and an app directory. The root directory only contains an app exe file and an ico file. jPackage copies all the files in the directory defined in the -input argument to the app directory including my properties file. 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. This was not a very user friendly list, but I was able to manually create the list of java modules I needed.

When I ran jdeps I got the error "Module java.activation not found, required by java.xml.bind". 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. 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. When I ran jDeps again it gave me a list of packages 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 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.

Step 3 - Packaging. I used the 21 dependencies identified in step 2 and built the installer using jPackage as follows:

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.

Directory Structure

目录结构

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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