Gradle jpackage creating unrunnable application

2

I am trying to run jpackage with a bare bones Gradle JavaFX application mostly to try things out. There is nothing special about it, its the IntelliJ JavaFX sample with Gradle added in. The application runs fine with gradlew clean build run. However, when creating a package with gradlew jpackage the resulting exe crashes instantly and creates an hs_err_pid.

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000000000000, pid=1132, tid=15340
#
# JRE version:  (15.0.2+10) (build )
# Java VM: OpenJDK 64-Bit Server VM (15.0.2+10, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C  0x0000000000000000

See full output here: https://pastebin.com/LgbSFa5L

I've tried the answers on a similar question but they did not work.

  • Copying zip.dll from {app}\runtime\bin to {app}\
  • Trying other JDKs
    • AdoptOpenJDK 11
    • AdoptOpenJDK 14
    • AdoptOpenJDK 15
    • BellSoft Liberica JDK 15

build.gradle looks like this

// Setup Gradle
plugins {
    id "application"
    id "org.beryx.runtime" version "1.12.2"
    id "org.openjfx.javafxplugin" version '0.0.9'
}

repositories {
    mavenCentral()
    jcenter()
}

// Setup application, dependencies
group = "io.mattw.sample"
sourceCompatibility = 15
targetCompatibility = 15

application {
    mainClassName = "io.mattw.sample.Main"
}

javafx {
    version = 15
    modules = ["javafx.base", "javafx.controls", "javafx.fxml"]
}

dependencies {

}

// Setup release
// https://simply-how.com/custom-java-runtime
runtime {
    addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
}

tasks.runtime.doLast {
    copy {
        from("src/main/resources")
        into("$buildDir/image/bin")
    }
}

Edit:

When running the exe with WinDbg (preview), I get the following output. Possibly relevant that I have Java 8 installed normally though I'd expect it to use the bundled SDK and not the systems.

Microsoft (R) Windows Debugger Version 10.0.21306.1007 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\gradle-test-javafx.exe

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00007ff6`995d0000 00007ff6`9963f000   image00007ff6`995d0000
ModLoad: 00007ffc`36450000 00007ffc`36646000   ntdll.dll
ModLoad: 00007ffc`35320000 00007ffc`353dd000   C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ffc`33d90000 00007ffc`34059000   C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ffc`36210000 00007ffc`363b0000   C:\WINDOWS\System32\USER32.dll
ModLoad: 00007ffc`33d30000 00007ffc`33d52000   C:\WINDOWS\System32\win32u.dll
ModLoad: 00007ffc`346f0000 00007ffc`3471a000   C:\WINDOWS\System32\GDI32.dll
ModLoad: 00007ffc`343a0000 00007ffc`344ab000   C:\WINDOWS\System32\gdi32full.dll
ModLoad: 00007ffc`33c90000 00007ffc`33d2d000   C:\WINDOWS\System32\msvcp_win.dll
ModLoad: 00007ffc`33b90000 00007ffc`33c90000   C:\WINDOWS\System32\ucrtbase.dll
ModLoad: 00007ffc`35ac0000 00007ffc`36202000   C:\WINDOWS\System32\SHELL32.dll
(4ad0.33e0): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ffc`36520670 cc              int     3
0:000> g
ModLoad: 00007ffc`355c0000 00007ffc`355f0000   C:\WINDOWS\System32\IMM32.DLL
ModLoad: 00007ffc`34ba0000 00007ffc`34c4e000   C:\WINDOWS\System32\shcore.dll
ModLoad: 00007ffc`35a20000 00007ffc`35abe000   C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00007ffc`34840000 00007ffc`34b96000   C:\WINDOWS\System32\combase.dll
ModLoad: 00007ffc`35720000 00007ffc`3584b000   C:\WINDOWS\System32\RPCRT4.dll
ModLoad: 00007ffc`11d50000 00007ffc`11d68000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jli.dll
ModLoad: 00007ffc`224e0000 00007ffc`22590000   C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.19041.488_none_4238de57f6b64d28\COMCTL32.dll
ModLoad: 00007ffc`22cb0000 00007ffc`22cc9000   C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
ModLoad: 00007ffc`34c50000 00007ffc`34cfc000   C:\WINDOWS\System32\ADVAPI32.dll
ModLoad: 00007ffc`35520000 00007ffc`355bc000   C:\WINDOWS\System32\sechost.dll
ModLoad: 00007ffc`10080000 00007ffc`10095000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\vcruntime140.dll
ModLoad: 00007ffb`f76b0000 00007ffb`f774b000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\msvcp140.dll
ModLoad: 00007ffb`a5030000 00007ffb`a5bbf000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\server\jvm.dll
ModLoad: 00007ffc`34630000 00007ffc`34638000   C:\WINDOWS\System32\PSAPI.DLL
ModLoad: 00007ffc`1ff10000 00007ffc`1ff19000   C:\WINDOWS\SYSTEM32\WSOCK32.dll
ModLoad: 00007ffc`32a70000 00007ffc`32a7a000   C:\WINDOWS\SYSTEM32\VERSION.dll
ModLoad: 00007ffc`261f0000 00007ffc`26217000   C:\WINDOWS\SYSTEM32\WINMM.dll
ModLoad: 00007ffc`35870000 00007ffc`358db000   C:\WINDOWS\System32\WS2_32.dll
ModLoad: 0000014c`22330000 0000014c`2239b000   C:\WINDOWS\System32\ws2_32.DLL
ModLoad: 00007ffc`32a30000 00007ffc`32a42000   C:\WINDOWS\SYSTEM32\kernel.appcore.dll
ModLoad: 00007ffc`2acf0000 00007ffc`2acfa000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jimage.dll
ModLoad: 00007ffc`22590000 00007ffc`22774000   C:\WINDOWS\SYSTEM32\DBGHELP.DLL
ModLoad: 00007ffc`21be0000 00007ffc`21c0c000   C:\WINDOWS\SYSTEM32\dbgcore.DLL
ModLoad: 00007ffc`34060000 00007ffc`340e0000   C:\WINDOWS\System32\bcryptPrimitives.dll
ModLoad: 00007ffc`09f50000 00007ffc`09f75000   C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\java.dll
(4ad0.30c4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
0000014c`23890969 8b06            mov     eax,dword ptr [rsi] ds:00000000`00000000=????????
0:004> g
(4ad0.30c4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for C:\GitHub\gradle-test-javafx\build\jpackage\gradle-test-javafx\runtime\bin\jimage.dll
00000000`00000000 ??              ???
0:004> g
ntdll!NtTerminateProcess+0x14:
00007ffc`364ecba4 c3              ret
java
gradle
javafx
java-11
jpackage
asked on Stack Overflow Mar 7, 2021 by Matthew Wright • edited Mar 11, 2021 by Matthew Wright

3 Answers

2

With Liberica I'm able to make it work by adding the following line:

runtime {
    addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
    addModules("javafx.base", "javafx.controls", "javafx.fxml") // <----
}

Without that, it seems like the javafx.controls module is not added to the generated runtime image (you can check that with runtime\bin\java.exe --list-modules).

Running the application manually, as well as through the generated exe works after that.


Without Liberica, I was able to get some more information by adding the --win-console option to jpackage as follows:

runtime {
    addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")

    jpackage {
        imageOptions = ["--win-console"] // <---
    }
}

Running the generated exe results in

Error: JavaFX runtime components are missing, and are required to run this application

Which I believe is a problem with the javafx modules not being put on the module path, but on the class path (which AFAIK is not supported nowadays). That seems to be a problem with the runtime plugin being used (which says it does not support modular applications).

I was able to manually make it work by adding

runtime {
    ...
    launcher {
        jvmArgs = ["--add-modules=javafx.base,javafx.controls,javafx.fxml"]
    }
}

And then manually copying the javafx jars to the app\mods folder (which I had to create). Looking at the generated {app}.cfg file jpackage creates that's what the launcher will use as module path. I also deleted the unneeded app.classpath entries for the javafx jars from the {app}.cfg file.

answered on Stack Overflow Mar 7, 2021 by Jorn Vernee • edited Mar 7, 2021 by Jorn Vernee
2

It is a JDK15 bug. Using JPackage from JDK16 fixed the problem for me.

answered on Stack Overflow Mar 11, 2021 by FlickIt
1

Combining both answers and waiting a bit for things to update fixed the issue for me.

  1. Upgraded Gradle to 7.0-RC-1 which has support for JDK 16 in gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-1-bin.zip
  1. Downloaded and using Liberica JDK 16 (@FlickIt)
  2. Using the addModules() fix for Liberica in the build.gradle (@Jorn Vernee)
runtime {
    addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
    addModules("javafx.base", "javafx.controls", "javafx.fxml", "javafx.graphics", "javafx.web")
}

Running jpackage in Gradle now produces a runnable JavaFX exe without needing to copy dlls!

If your application has more than just JavaFX as a dependency, change #3 to ALL-MODULE-PATH. It makes the packaged files/app much larger but will allow it to run.

runtime {
    addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
    addModules("ALL-MODULE-PATH")
}
answered on Stack Overflow Mar 25, 2021 by Matthew Wright • edited Mar 26, 2021 by Matthew Wright

User contributions licensed under CC BY-SA 3.0