fvarrui / JavaPackager

:package: Gradle/Maven plugin to package Java applications as native Windows, MacOS, or Linux executables and create installers for them.
GNU General Public License v3.0
1.03k stars 131 forks source link

With "org.apache.poi" in my project, there is always "module not found" error occured #399

Closed payfish closed 2 months ago

payfish commented 5 months ago

I'm submitting a…

Well i import this org.apache.poi dependency to my project to export a word file.

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>5.2.3</version>
    </dependency>

But it comes to an error when i was packaging the proj, i try to import the module which was not founded, but it always comes out another "module not found" error.

[ERROR]  Exception in thread "main" java.lang.module.FindException: Module commons.math3 not found, required by org.apache.poi.poi

I guess there is a conflict between "org.apache.poi" and JavaPackager because when i deleted the dependency, the Packager works correctly.

Please tell us about your environment:

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

chenyany commented 5 months ago

I also encountered the same problem.

fvarrui commented 4 months ago

Hi @chenyany and @payfish! I haven't found a solution for this issue yet ... a work around is to set customizedJre=false and bundle a full JRE, or manually specify modules (but this is a bit tedious). jdeps is used to find out which core modules are needed in order to generate a minimal JRE, including only those core modules, but not sure why some non-modular JARs cause this problem. I'd really appreciate it if you could give me some hint on what options JP should pass to jdeps to solve this problem. Thanks!

fvarrui commented 4 months ago

259

fvarrui commented 4 months ago

I researched again about this issue and found this answer in StackOverflow, then I tried to add --add-modules=ALL-MODULE-PATH to jdeps call as explained, and it seems to be working fine. 😮

I've only tried adding the poi-ooml dependency to the pom.xml file and it bundles a customized JRE without errors, so I released a SNAPSHOT version, so you can check it: 1.7.6-20240416.203813-5.

Changes were pushed into issue-399 branch.

Please, give me some feedback.

Thanks!!

fvarrui commented 4 months ago

Doing some tests I just realized that jdeps can't find all needed modules when using a fat jar 😢

When using a normal jar with dependencies in libs folder, app runs fine:

C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven>jre\bin\java -jar HelloWorldMaven-1.0.0-runnable.jar
Starting app ...
PATH=C:\Program Files\Eclipse Adoptium\jdk-21.0.2.13-hotspot\bin;C:\tools\ruby33\bin;C:\Python312\Scripts\;C:\Python312\;C:\Program Files\GraalVM\graalvm-community-openjdk-21.0.2+13.1\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.6\bin;C:\Program Files\Eclipse Adoptium\jdk-19.0.2.7-hotspot\bin;C:\Program Files\Eclipse Adoptium\jdk-20.0.2.9-hotspot\bin;C:\tools\ruby31\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Microchip\xc8\v2.36\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.6\bin;C:\Program Files\Vagrant\bin;C:\ProgramData\nvm;C:\Program Files\nodejs;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Git\cmd;C:\Program Files\Go\bin;C:\Users\fvarrui\AppData\Local\Microsoft\WindowsApps;C:\Users\fvarrui\AppData\Local\GitHubDesktop\bin;C:\Program Files\OpenSSL-Win64\bin;C:\Program Files (x86)\Nmap;C:\Program Files\Oracle\VirtualBox;C:\Program Files (x86)\WiX Toolset v3.11\bin;C:\Program Files\Imaginando\DRC;C:\ProgramData\chocolatey\lib\wmiexplorer\tools;C:\ProgramData\nvm;C:\Program Files\nodejs;C:\Users\fvarrui\go\bin

C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven>jre\bin\java --list-modules
java.base@21.0.2
java.datatransfer@21.0.2
java.desktop@21.0.2
java.logging@21.0.2
java.naming@21.0.2
java.prefs@21.0.2
java.security.jgss@21.0.2
java.security.sasl@21.0.2
java.xml@21.0.2
java.xml.crypto@21.0.2
jdk.internal.vm.ci@21.0.2

When using fat jar, app fails due to missing modules in JRE:

C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven>jre\bin\java -jar HelloWorldMaven-1.0.0-jar-with-dependencies.jar
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/logging/Logger
        at com.sun.jna.Native.<clinit>(Native.java:114)
        at io.github.fvarrui.helloworld.Main.<clinit>(Main.java:21)
Caused by: java.lang.ClassNotFoundException: java.util.logging.Logger
        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)
        ... 2 more

C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven>jre\bin\java --list-modules
java.base@21.0.2
jdk.internal.vm.ci@21.0.2
payfish commented 4 months ago

Thank you!! Things works well with the SNAPSHOT version! But here is some little question: when I import the SNAPSHOT plugin I encountered an "Unresolved plugin" error, but I can still package my proj with it, despite the maven sync error.

payfish commented 4 months ago

I'm not familiar with jdeps so I'm sorry that I can't help, But I believe you have found out the correct anwser to solve this problem. Your work helps me a lot! I appreciate for your time and thank you truely!

fvarrui commented 4 months ago

Thank you!! Things works well with the SNAPSHOT version! But here is some little question: when I import the SNAPSHOT plugin I encountered an "Unresolved plugin" error, but I can still package my proj with it, despite the maven sync error.

Please, could you post here the error message?

fvarrui commented 4 months ago

I'm not familiar with jdeps so I'm sorry that I can't help, But I believe you have found out the correct anwser to solve this problem. Your work helps me a lot! I appreciate for your time and thank you truely!

Thanks to you for helping to improve JP

payfish commented 4 months ago

Thank you!! Things works well with the SNAPSHOT version! But here is some little question: when I import the SNAPSHOT plugin I encountered an "Unresolved plugin" error, but I can still package my proj with it, despite the maven sync error.

Please, could you post here the error message?

Ofcourse! Maven has downloaded the SNAPSHOT version correctly(I can find it in my local repo). But it still get this error when synchronizing, I tried so many ways but still can't fix it, probably an issue with my configuration. Whatever, it works, I just ignore the error and do the package it works good. thanks!

Unresolved plugin: 'io.github.fvarrui:javapackager:1.7.6-20240416.203813-5'
fvarrui commented 4 months ago

Ofcourse! Maven has downloaded the SNAPSHOT version correctly(I can find it in my local repo). But it still get this error when synchronizing, I tried so many ways but still can't fix it, probably an issue with my configuration. Whatever, it works, I just ignore the error and do the package it works good. thanks!

Unresolved plugin: 'io.github.fvarrui:javapa

I think it's due to the snapshot version, Maven can't find the plugin in the main repository (unresooved plugin), but in the snapshots one. When the stable version is released to Maven Central, we can check it and confirm this.

fvarrui commented 4 months ago

Branch issue-399 merged into devel, ready to be released

sproket commented 3 months ago

How can I test out your pre-release for 1.7.6?

payfish commented 3 months ago

How can I test out your pre-release for 1.7.6?

https://github.com/fvarrui/JavaPackager?tab=readme-ov-file#how-to-use-snapshot-versions

sproket commented 3 months ago

Nice! The version you mentioned fixed this for me on Windows. 50 megs saved! On Mac I get:

jlink --module-path=/Library/Java/JavaVirtualMachines/jdk-21.0.1.jdk/Contents/Home/jmods --add-modules java.base,java.management,java.naming,java.prefs,java.scripting,java.sql,jdk.unsupported,jdk.unsupported.desktop --output /Users/danhoward/projects/goldchest/target/goldchest/goldchest.app/Contents/PlugIns/jre.jre/Contents/Home --no-header-files --no-man-pages --strip-debug --release-info add:IMAGE_TYPE="JRE":OS_ARCH="x86_64":OS_NAME=Darwin"

   /bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
[ERROR]         /bin/sh: -c: line 1: syntax error: unexpected end of file

It looks like you have an extra " at the end of the command. I tried with the latest 1.7.6-20240430.234925-8 and that issue is still there.

Thanks

Nonoas commented 3 months ago

I researched again about this issue and found this answer in StackOverflow, then I tried to add --add-modules=ALL-MODULE-PATH to jdeps call as explained, and it seems to be working fine. 😮

I've only tried adding the poi-ooml dependency to the pom.xml file and it bundles a customized JRE without errors, so I released a SNAPSHOT version, so you can check it: 1.7.6-20240416.203813-5.

Changes were pushed into issue-399 branch.

Please, give me some feedback.

Thanks!!

I get a error with this snapshot,it happens when I used the jre to run the exe file. I also tried double-clicking it, but nothing happened:

Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
        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/sql/DataSource
        at org.flywaydb.core.api.configuration.FluentConfiguration.<init>(FluentConfiguration.java:51)
        at org.flywaydb.core.Flyway.configure(Flyway.java:88)
        at indi.nonoas.worktools.config.FlyWayMigration.migrate(FlyWayMigration.kt:11)
        at indi.nonoas.worktools.App.dbMigrate(App.kt:108)
        at indi.nonoas.worktools.App.start(App.kt:89)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
        at java.base/java.security.AccessController.doPrivileged(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
        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)
        ... 14 more
fvarrui commented 2 months ago

v1.7.6 released to Maven Central