Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erro “require java runtime environment......” in 1.7.6-SNAPSHOT #412

Closed
Nonoas opened this issue May 25, 2024 Discussed in #411 · 8 comments
Closed

Erro “require java runtime environment......” in 1.7.6-SNAPSHOT #412

Nonoas opened this issue May 25, 2024 Discussed in #411 · 8 comments
Labels
feedback Waiting for feedback

Comments

@Nonoas
Copy link

Nonoas commented May 25, 2024

Discussed in #411

Originally posted by Nonoas May 25, 2024
I get the error too:
image

plugin: io.github.fvarrui:javapackager:1.7.6-SNAPSHOT
config:

tasks.register('packageMyApp', PackageTask) {
    dependsOn clean, jar
    // mandatory
    mainClass = mainClassName
    // optional
    modules = ["java.base", "java.management", "java.net.http", "java.scripting", "java.sql", "java.naming",
               "jdk.jsobject", "jdk.unsupported", "jdk.unsupported.desktop", "jdk.xml.dom"]
    bundleJre = true
    generateInstaller = false
    administratorRequired = false
    winConfig { createZipball = true }

}
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

But, it works when i using .\jre\bin\java -jar worktools.exe to run it. so i think maybe the jre is no problem, and i don1t know have to fix

@fvarrui
Copy link
Owner

fvarrui commented May 31, 2024

Hi @Nonoas!
I'll try to reproduce your issue and tell you something asap

@fvarrui
Copy link
Owner

fvarrui commented Jun 2, 2024

I'm not able to reproduce your issue. I've just build an app with and without a JRE using Gradle and all seems to be working fine. I need more details or maybe a sample app.

@fvarrui fvarrui added the question Further information is requested label Jun 2, 2024
@Nonoas
Copy link
Author

Nonoas commented Aug 17, 2024

I'm not able to reproduce your issue. I've just build an app with and without a JRE using Gradle and all seems to be working fine. I need more details or maybe a sample app.

just now, i reproduce this issue with javapackager1.7.6 release, there is the project reproduced:https://github.com/Nonoas/work-tools/tree/error_with_jp1.7.6

@Nonoas
Copy link
Author

Nonoas commented Aug 17, 2024

I'm not able to reproduce your issue. I've just build an app with and without a JRE using Gradle and all seems to be working fine. I need more details or maybe a sample app.

just now, i reproduce this issue with javapackager1.7.6 release, there is the project reproduced:https://github.com/Nonoas/work-tools/tree/error_with_jp1.7.6

runtime info :

C:\Users\13569\Desktop>echo %JAVA_HOME%
D:\RUNTIME\Local\Java\jdk17

C:\Users\13569\Desktop>java -version
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

@fvarrui
Copy link
Owner

fvarrui commented Sep 1, 2024

Hi @Nonoas!

Sorry for my late reply, but I'm back with a solution!

I managed to build your app without problems (just cloned and built it with Gradle):

C:\Users\fvarrui\GitHub\work-tools>gradle packageMyApp

> Task :compileKotlin
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\common\DataBinder.kt: (64, 34): Unchecked cast: Any! to Property<out Nothing>
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\global\FuncManager.kt: (29, 54): Unchecked cast: Any? to List<Map<String, Any>>
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\BeanUtil.kt: (20, 26): 'newInstance(): T!' is deprecated. Deprecated in Java
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\ClassUtil.kt: (63, 13): Variable 'packageLength' is never used
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\ClassUtil.kt: (81, 13): Name shadowed: packageName
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\FileUtil.kt: (92, 13): Name shadowed: dirPath
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (90, 54): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (93, 48): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (117, 45): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (128, 37): Parameter 'integer' is never used, could be renamed to _

> Task :compileJava
Note: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\ext\PluginLoader.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :packageMyApp
Using packager io.github.fvarrui.javapackager.packagers.WindowsPackager
Creating app ...
    Initializing packager ...
        PackagerSettings [outputDirectory=C:\Users\fvarrui\GitHub\work-tools\build, licenseFile=null, iconFile=null, generateInstaller=false, forceInstaller=false, mainClass=indi.nonoas.worktools.MainKt, name=worktools, displayName=worktools, version=1.3.3, description=worktools, url=null, administratorRequired=false, organizationName=ACME, organizationUrl=, organizationEmail=, bundleJre=true, customizedJre=true, jrePath=null, jdkPath=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1, additionalResources=[], modules=[], additionalModules=[], platform=windows, envPath=null, vmArgs=[], runnableJar=null, copyDependencies=true, jreDirectoryName=jre, winConfig=WindowsConfig [icoFile=null, headerType=gui, companyName=ACME, copyright=ACME, fileDescription=worktools, fileVersion=1.0.0.0, internalName=worktools, language=null, originalFilename=worktools.exe, productName=worktools, productVersion=1.0.0.0, trademarks=ACME, txtFileVersion=1.3.3, txtProductVersion=1.3.3, shortcutName=worktools, disableDirPage=true, disableProgramGroupPage=true, disableFinishedPage=true, disableRunAfterInstall=true, disableWelcomePage=true, createDesktopIconTask=true, generateSetup=true, generateMsi=true, generateMsm=false, msiUpgradeCode=27eea3ce-3dc1-41e7-ad7e-e8863d6793d2, wrapJar=true, setupLanguages={english=compiler:Default.isl, spanish=compiler:Languages\Spanish.isl}, setupMode=installForAllUsers, signing=null, registry=Registry [entries=[]], removeOldLibs=false, exeCreationTool=launch4j, vmLocation=null], linuxConfig=null, macConfig=null, createTarball=false, tarballName=null, createZipball=true, zipballName=null, extra={}, useResourcesAsWorkingDir=true, assetsDir=C:\Users\fvarrui\GitHub\work-tools\assets, classpath=null, jreMinVersion=null, manifest=Manifest [additionalEntries={}, sections=[]], additionalModulePaths=[], fileAssociations=null, packagingJdk=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1, scripts=Scripts [bootstrap=null, preInstall=null, postInstall=null], arch=x64, templates=null]
    Packager initialized!

    Creating app structure ...
        App folder created: C:\Users\fvarrui\GitHub\work-tools\build\worktools
        Assets folder created: C:\Users\fvarrui\GitHub\work-tools\build\assets
    App structure created!

    Resolving resources ...
        No license file specified
        Icon file resolved: C:\Users\fvarrui\GitHub\work-tools\assets\windows\worktools.ico
        Skipped adding the icon file as additional resource because the target platform is Windows
        Effective additional resources []
    Resources resolved!

    Copying additional resources
    All additional resources copied!

    Copying all dependencies ...
    Dependencies copied to C:\Users\fvarrui\GitHub\work-tools\build\worktools\libs!

    Creating runnable JAR...
    Runnable jar created in C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar!

    Bundling JRE ... with C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1
        Creating customized JRE ...
        Getting required modules ...
            Executing command: cmd.exe /s /c ""C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\bin\jdeps" -q --multi-release 22 --ignore-missing-deps --print-module-deps --add-modules=ALL-MODULE-PATH --module-path=C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar;C:\Users\fvarrui\GitHub\work-tools\build\worktools\libs"
            java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop
        Required modules found: [java.base, java.logging, java.management, jdk.unsupported, jdk.unsupported.desktop]

        Creating JRE with next modules included: java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop
        Using C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\jmods modules directory
        Executing command: cmd.exe /s /c ""C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\bin\jlink" "--module-path=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\jmods" --add-modules java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop --output C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre --no-header-files --no-man-pages --strip-debug --release-info add:IMAGE_TYPE="JRE":OS_ARCH="x86_64":OS_NAME="Windows""
        Removing folder [C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre\legal]
    JRE bundled in C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre!

    Creating windows EXE ... with launch4j
        Exe manifest file generated in C:\Users\fvarrui\GitHub\work-tools\build\assets\worktools.exe.manifest!
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\assets\worktools.exe.manifest] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.exe.manifest]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\assets\windows\worktools.ico] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.ico]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.jar]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.exe] to file [C:\Users\fvarrui\GitHub\work-tools\build\worktools\worktools.exe]
        No signing configuration found
    Windows EXE file created in C:\Users\fvarrui\GitHub\work-tools\build\worktools\worktools.exe!

App created in C:\Users\fvarrui\GitHub\work-tools\build\worktools!

Installer generation is disabled by 'generateInstaller' property!
Creating bundles ...
    Zipball created: C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-windows.zip
Bundles created!


Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 1m 53s
7 actionable tasks: 6 executed, 1 up-to-date

This is my environment:

C:\Users\fvarrui\GitHub\work-tools>gradle -v

------------------------------------------------------------
Gradle 8.8
------------------------------------------------------------

Build time:   2024-05-31 21:46:56 UTC
Revision:     4bd1b3d3fc3f31db5a26eecb416a165b8cc36082

Kotlin:       1.9.22
Groovy:       3.0.21
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          22.0.2 (GraalVM Community 22.0.2+9-jvmci-b01)
OS:           Windows 11 10.0 amd64

But the EXE was not working nor showing any output ... how to deal with this problem (maybe this could help you in the future):

  1. Set winConfig.headerType=console, so, when running your EXE from console it shows output.
  2. Build and run EXE again:
C:\Users\fvarrui\GitHub\work-tools>build\worktools\worktools.exe
Sep 01, 2024 10:10:48 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @44cbf144'
WARN StatusConsoleListener JNDI lookup class is not available because this JRE does not support JNDI. JNDI string lookups will not be available, continuing configuration. Ignoring java.lang.NoClassDefFoundError: javax/naming/Context
Exception in Application init method
Exception in thread "main" java.lang.RuntimeException: Exception in Application init method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:888)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/naming/NamingException
        at indi.nonoas.worktools.utils.DBUtil.init(DBUtil.kt:24)
        at indi.nonoas.worktools.App.init(App.kt:86)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:817)
        ... 2 more
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 5 more

Aha!!! There's a missing module ... in this case was java.naming.
3. Let's check:

C:\Users\fvarrui\GitHub\work-tools>build\worktools\jre\bin\java --list-modules
java.base@22.0.2
java.datatransfer@22.0.2
java.desktop@22.0.2
java.logging@22.0.2
java.management@22.0.2
java.prefs@22.0.2
java.xml@22.0.2
jdk.internal.vm.ci@22.0.2
jdk.unsupported@22.0.2
jdk.unsupported.desktop@22.0.2

Then I saw in your build.gradle that there were probably other missing modules .... so, I added all of them to JP config using additionalModules property:

tasks.register('packageMyApp', PackageTask) {
    dependsOn clean, jar
    // mandatory
    mainClass = mainClassName
    // optional
//    modules = ["java.base", "java.management", "java.net.http", "java.scripting", "java.sql", "java.naming",
//               "jdk.jsobject", "jdk.unsupported", "jdk.unsupported.desktop", "jdk.xml.dom"]
    additionalModules = [ "java.net.http", "java.scripting", "java.sql", "java.naming", "jdk.jsobject", "jdk.xml.dom" ]
    bundleJre = true
    generateInstaller = false
    administratorRequired = false
    winConfig { 
        headerType = 'console'
    }
    createZipball = true 
}

This happens because JP<=1.7.6 is not able to find all required modules (there's a patch in 1.7.7 for this issue, but not released yet). I hope JP 1.7.7 fixes this issue and you can remove additionalModules.

  1. Finally built and tried to run the EXE again:
    image
    And voilà!

Now your bundled JRE has all required modules:

C:\Users\fvarrui\GitHub\work-tools>build\worktools\jre\bin\java --list-modules
java.base@22.0.2
java.datatransfer@22.0.2
java.desktop@22.0.2
java.logging@22.0.2
java.management@22.0.2
java.naming@22.0.2
java.net.http@22.0.2
java.prefs@22.0.2
java.scripting@22.0.2
java.security.sasl@22.0.2
java.sql@22.0.2
java.transaction.xa@22.0.2
java.xml@22.0.2
jdk.internal.vm.ci@22.0.2
jdk.jsobject@22.0.2
jdk.unsupported@22.0.2
jdk.unsupported.desktop@22.0.2
jdk.xml.dom@22.0.2

@fvarrui fvarrui added feedback Waiting for feedback and removed question Further information is requested labels Sep 1, 2024
@Nonoas
Copy link
Author

Nonoas commented Sep 4, 2024

Hi @Nonoas!

Sorry for my late reply, but I'm back with a solution!

I managed to build your app without problems (just cloned and built it with Gradle):

C:\Users\fvarrui\GitHub\work-tools>gradle packageMyApp

> Task :compileKotlin
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\common\DataBinder.kt: (64, 34): Unchecked cast: Any! to Property<out Nothing>
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\global\FuncManager.kt: (29, 54): Unchecked cast: Any? to List<Map<String, Any>>
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\BeanUtil.kt: (20, 26): 'newInstance(): T!' is deprecated. Deprecated in Java
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\ClassUtil.kt: (63, 13): Variable 'packageLength' is never used
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\ClassUtil.kt: (81, 13): Name shadowed: packageName
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\utils\FileUtil.kt: (92, 13): Name shadowed: dirPath
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (90, 54): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (93, 48): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (117, 45): Parameter 'event' is never used, could be renamed to _
w: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\view\workspace\ModifyListView.kt: (128, 37): Parameter 'integer' is never used, could be renamed to _

> Task :compileJava
Note: C:\Users\fvarrui\GitHub\work-tools\src\main\java\indi\nonoas\worktools\ext\PluginLoader.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :packageMyApp
Using packager io.github.fvarrui.javapackager.packagers.WindowsPackager
Creating app ...
    Initializing packager ...
        PackagerSettings [outputDirectory=C:\Users\fvarrui\GitHub\work-tools\build, licenseFile=null, iconFile=null, generateInstaller=false, forceInstaller=false, mainClass=indi.nonoas.worktools.MainKt, name=worktools, displayName=worktools, version=1.3.3, description=worktools, url=null, administratorRequired=false, organizationName=ACME, organizationUrl=, organizationEmail=, bundleJre=true, customizedJre=true, jrePath=null, jdkPath=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1, additionalResources=[], modules=[], additionalModules=[], platform=windows, envPath=null, vmArgs=[], runnableJar=null, copyDependencies=true, jreDirectoryName=jre, winConfig=WindowsConfig [icoFile=null, headerType=gui, companyName=ACME, copyright=ACME, fileDescription=worktools, fileVersion=1.0.0.0, internalName=worktools, language=null, originalFilename=worktools.exe, productName=worktools, productVersion=1.0.0.0, trademarks=ACME, txtFileVersion=1.3.3, txtProductVersion=1.3.3, shortcutName=worktools, disableDirPage=true, disableProgramGroupPage=true, disableFinishedPage=true, disableRunAfterInstall=true, disableWelcomePage=true, createDesktopIconTask=true, generateSetup=true, generateMsi=true, generateMsm=false, msiUpgradeCode=27eea3ce-3dc1-41e7-ad7e-e8863d6793d2, wrapJar=true, setupLanguages={english=compiler:Default.isl, spanish=compiler:Languages\Spanish.isl}, setupMode=installForAllUsers, signing=null, registry=Registry [entries=[]], removeOldLibs=false, exeCreationTool=launch4j, vmLocation=null], linuxConfig=null, macConfig=null, createTarball=false, tarballName=null, createZipball=true, zipballName=null, extra={}, useResourcesAsWorkingDir=true, assetsDir=C:\Users\fvarrui\GitHub\work-tools\assets, classpath=null, jreMinVersion=null, manifest=Manifest [additionalEntries={}, sections=[]], additionalModulePaths=[], fileAssociations=null, packagingJdk=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1, scripts=Scripts [bootstrap=null, preInstall=null, postInstall=null], arch=x64, templates=null]
    Packager initialized!

    Creating app structure ...
        App folder created: C:\Users\fvarrui\GitHub\work-tools\build\worktools
        Assets folder created: C:\Users\fvarrui\GitHub\work-tools\build\assets
    App structure created!

    Resolving resources ...
        No license file specified
        Icon file resolved: C:\Users\fvarrui\GitHub\work-tools\assets\windows\worktools.ico
        Skipped adding the icon file as additional resource because the target platform is Windows
        Effective additional resources []
    Resources resolved!

    Copying additional resources
    All additional resources copied!

    Copying all dependencies ...
    Dependencies copied to C:\Users\fvarrui\GitHub\work-tools\build\worktools\libs!

    Creating runnable JAR...
    Runnable jar created in C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar!

    Bundling JRE ... with C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1
        Creating customized JRE ...
        Getting required modules ...
            Executing command: cmd.exe /s /c ""C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\bin\jdeps" -q --multi-release 22 --ignore-missing-deps --print-module-deps --add-modules=ALL-MODULE-PATH --module-path=C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar;C:\Users\fvarrui\GitHub\work-tools\build\worktools\libs"
            java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop
        Required modules found: [java.base, java.logging, java.management, jdk.unsupported, jdk.unsupported.desktop]

        Creating JRE with next modules included: java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop
        Using C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\jmods modules directory
        Executing command: cmd.exe /s /c ""C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\bin\jlink" "--module-path=C:\Program Files\GraalVM\graalvm-community-openjdk-22.0.2+9.1\jmods" --add-modules java.base,java.logging,java.management,jdk.unsupported,jdk.unsupported.desktop --output C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre --no-header-files --no-man-pages --strip-debug --release-info add:IMAGE_TYPE="JRE":OS_ARCH="x86_64":OS_NAME="Windows""
        Removing folder [C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre\legal]
    JRE bundled in C:\Users\fvarrui\GitHub\work-tools\build\worktools\jre!

    Creating windows EXE ... with launch4j
        Exe manifest file generated in C:\Users\fvarrui\GitHub\work-tools\build\assets\worktools.exe.manifest!
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\assets\worktools.exe.manifest] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.exe.manifest]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\assets\windows\worktools.ico] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.ico]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-runnable.jar] to file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.jar]
        Copying file [C:\Users\fvarrui\GitHub\work-tools\build\launch4j\app.exe] to file [C:\Users\fvarrui\GitHub\work-tools\build\worktools\worktools.exe]
        No signing configuration found
    Windows EXE file created in C:\Users\fvarrui\GitHub\work-tools\build\worktools\worktools.exe!

App created in C:\Users\fvarrui\GitHub\work-tools\build\worktools!

Installer generation is disabled by 'generateInstaller' property!
Creating bundles ...
    Zipball created: C:\Users\fvarrui\GitHub\work-tools\build\worktools-1.3.3-windows.zip
Bundles created!


Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 1m 53s
7 actionable tasks: 6 executed, 1 up-to-date

This is my environment:

C:\Users\fvarrui\GitHub\work-tools>gradle -v

------------------------------------------------------------
Gradle 8.8
------------------------------------------------------------

Build time:   2024-05-31 21:46:56 UTC
Revision:     4bd1b3d3fc3f31db5a26eecb416a165b8cc36082

Kotlin:       1.9.22
Groovy:       3.0.21
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          22.0.2 (GraalVM Community 22.0.2+9-jvmci-b01)
OS:           Windows 11 10.0 amd64

But the EXE was not working nor showing any output ... how to deal with this problem (maybe this could help you in the future):

  1. Set winConfig.headerType=console, so, when running your EXE from console it shows output.
  2. Build and run EXE again:
C:\Users\fvarrui\GitHub\work-tools>build\worktools\worktools.exe
Sep 01, 2024 10:10:48 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @44cbf144'
WARN StatusConsoleListener JNDI lookup class is not available because this JRE does not support JNDI. JNDI string lookups will not be available, continuing configuration. Ignoring java.lang.NoClassDefFoundError: javax/naming/Context
Exception in Application init method
Exception in thread "main" java.lang.RuntimeException: Exception in Application init method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:888)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/naming/NamingException
        at indi.nonoas.worktools.utils.DBUtil.init(DBUtil.kt:24)
        at indi.nonoas.worktools.App.init(App.kt:86)
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:817)
        ... 2 more
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 5 more

Aha!!! There's a missing module ... in this case was java.naming. 3. Let's check:

C:\Users\fvarrui\GitHub\work-tools>build\worktools\jre\bin\java --list-modules
java.base@22.0.2
java.datatransfer@22.0.2
java.desktop@22.0.2
java.logging@22.0.2
java.management@22.0.2
java.prefs@22.0.2
java.xml@22.0.2
jdk.internal.vm.ci@22.0.2
jdk.unsupported@22.0.2
jdk.unsupported.desktop@22.0.2

Then I saw in your build.gradle that there were probably other missing modules .... so, I added all of them to JP config using additionalModules property:

tasks.register('packageMyApp', PackageTask) {
    dependsOn clean, jar
    // mandatory
    mainClass = mainClassName
    // optional
//    modules = ["java.base", "java.management", "java.net.http", "java.scripting", "java.sql", "java.naming",
//               "jdk.jsobject", "jdk.unsupported", "jdk.unsupported.desktop", "jdk.xml.dom"]
    additionalModules = [ "java.net.http", "java.scripting", "java.sql", "java.naming", "jdk.jsobject", "jdk.xml.dom" ]
    bundleJre = true
    generateInstaller = false
    administratorRequired = false
    winConfig { 
        headerType = 'console'
    }
    createZipball = true 
}

This happens because JP<=1.7.6 is not able to find all required modules (there's a patch in 1.7.7 for this issue, but not released yet). I hope JP 1.7.7 fixes this issue and you can remove additionalModules.

  1. Finally built and tried to run the EXE again:
    image
    And voilà!

Now your bundled JRE has all required modules:

C:\Users\fvarrui\GitHub\work-tools>build\worktools\jre\bin\java --list-modules
java.base@22.0.2
java.datatransfer@22.0.2
java.desktop@22.0.2
java.logging@22.0.2
java.management@22.0.2
java.naming@22.0.2
java.net.http@22.0.2
java.prefs@22.0.2
java.scripting@22.0.2
java.security.sasl@22.0.2
java.sql@22.0.2
java.transaction.xa@22.0.2
java.xml@22.0.2
jdk.internal.vm.ci@22.0.2
jdk.jsobject@22.0.2
jdk.unsupported@22.0.2
jdk.unsupported.desktop@22.0.2
jdk.xml.dom@22.0.2

Thank you very much for your patience!!!

@fvarrui
Copy link
Owner

fvarrui commented Sep 4, 2024

Can we close this issue?

@Nonoas
Copy link
Author

Nonoas commented Sep 4, 2024

ok,thanks

@Nonoas Nonoas closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback Waiting for feedback
Projects
None yet
Development

No branches or pull requests

2 participants