-
Notifications
You must be signed in to change notification settings - Fork 133
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
Fat Jar doesn't seem to work as expected #403
Comments
Hi @EasyG0ing1! [INFO] Using runnable JAR: /mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/HelloWorldMaven-1.0.0-jar-with-dependencies.jar
[...]
[INFO] Creating GNU/Linux executable ...
[INFO] Rendering desktop file to /mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/assets/HelloWorldMaven.desktop
[INFO] Rendering mime.xml file to /mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/assets/HelloWorldMaven.xml
[INFO] Startup script generated in /mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/assets/startup.sh
[INFO] Concatenating files [/mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/assets/startup.sh,/mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/HelloWorldMaven-1.0.0-jar-with-dependencies.jar] into file [/mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/HelloWorldMaven/HelloWorldMaven]
[INFO] GNU/Linux executable created in /mnt/c/Users/fvarrui/GitHub/HelloWorldMaven/target/HelloWorldMaven/HelloWorldMaven! Plugins config here: <!-- creates runnable fat jar: HelloWorldMaven-1.0.0-SNAPSHOT-jar-with-dependencies.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<mainClass>${exec.mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>1.7.5</version>
<!--
<version>1.7.6-20240225.211252-1</version>
-->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<platform>linux</platform>
<bundleJre>true</bundleJre>
<customizedJre>true</customizedJre>
<generateInstaller>false</generateInstaller>
<administratorRequired>false</administratorRequired>
<!--
<jdkPath>C:\Users\fvarrui\jdks\mac\aarch64\jdk-21.0.2+13\Contents\Home</jdkPath>
-->
<additionalResources>
<additionalResource>src/main/resources/info.txt</additionalResource>
<additionalResource>HelloWorldMaven.l4j.ini</additionalResource>
</additionalResources>
<runnableJar>${project.build.directory}/${project.artifactId}-${project.version}-jar-with-dependencies.jar</runnableJar>
<copyDependencies>false</copyDependencies>
<vmArgs>
<vmArg>-Dcustom.variable="Hi!"</vmArg>
<vmArg>-Dother.custom.variable="Bye!"</vmArg>
</vmArgs>
<fileAssociations>
<fileAssociation>
<description>HelloWorld File</description>
<extension>hello</extension>
<mimeType>application/hello</mimeType>
</fileAssociation>
</fileAssociations>
<!--
<jrePath>C:\Users\fvarrui\jdks\windows\jdk-11.0.22+7-jre</jrePath>
-->
<arch>x64</arch>
<winConfig>
<headerType>gui</headerType>
<exeCreationTool>launch4j</exeCreationTool>
<icoFile>src/main/resources/HelloWorldMaven.ico</icoFile>
<generateSetup>true</generateSetup>
<generateMsi>false</generateMsi>
</winConfig>
<createZipball>false</createZipball>
<createTarball>false</createTarball>
</configuration>
</execution>
</executions>
</plugin> |
I think I know what's happening .... have a look!!! 😄 Your generated fat jar is: [INFO] --- assembly:3.7.1:single (make-assembly) @ iGet ---
[INFO] Building jar: /home/michael/java/iGet/target/iGet-2.0.0-jar-with-dependencies.jar and the jar which JP is referencing is <runnableJar>${build.directory}/${artifactId}-${project.version}.jar-with-dependencies.jar</runnableJar> runnableJar=/home/michael/java/iGet/target/iGet-2.0.0.jar-with-dependencies.jar,
^ This is "correct and the file exists" ;-D But I realized that JP should warn about this situation and/or stop the building process if |
Here is the problem: JavaPackager/src/main/java/io/github/fvarrui/javapackager/packagers/Packager.java Lines 402 to 410 in f01e4f0
It creates a runnableJar if it's null or doesn't exist (without any warning) ... just continues. I've just fixed and now the building process is stopped if it's not able to find the specified runnable jar ... snapshot version JavaPackager/src/main/java/io/github/fvarrui/javapackager/packagers/Packager.java Lines 397 to 407 in 7de5a56
Please, try it and give me some feedback. |
@fvarrui I see it and it makes sense. Yeah had it told me that it couldn't find my jar, I would have looked into that deeper, but it seemed to me that everything was in order so I didn't catch the slight mis-name in the jar file. I'll give the fix a try and let you know how it works out. |
@fvarrui I fixed the name of the fat jar in the POM file and re-ran the package with 1.7.5 which worked fine and it did use the fat jar. But then when I simply changed the version of JP to 1.7.6-SNAPSHOT, it errors out. This zip file has the output from each version for your review. |
@fvarrui Also, when I say that it worked fine with 1.7.5, I meant there were no errors making the michael@ubuntudt:~/Downloads$ sudo dpkg -i iget_2.0.0.deb
Selecting previously unselected package iget.
(Reading database ... 211479 files and directories currently installed.)
Preparing to unpack iget_2.0.0.deb ...
Unpacking iget (2.0.0) ...
Setting up iget (2.0.0) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
michael@ubuntudt:~/Downloads$ iget
Error: Unable to initialize main class com.simtechdata.Main
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException But when I run the jar file by itself, it works fine: michael@ubuntudt:~/java/iGet$ java --enable-preview -jar target/iGet-jar-with-dependencies.jar
Add URLs to the list simply by typing:
iget http://www.someserver.com/some/link - Add a link to the que
iget get http://www.someserver.com/some/link - Download link immediately
(http must begin the link to be recognized as a link)
Options:
get - Download links in que
get <url> - download one URL right now
watch - Watch mode looks for links to show up in clipboard then downloads them
setFolder - Set the folder where downloads get stored
[...] |
@fvarrui And some more details that might help... When I configure JP so that it handles the jar packaging on its own, the resulting Here is the pom setup for that scenario: <configuration>
<mainClass>${mainClass}</mainClass>
<bundleJre>true</bundleJre>
<customizedJre>false</customizedJre>
<copyDependencies>true</copyDependencies>
<platform>linux</platform>
<name>iget</name>
<vmArgs>
<arg>--enable-preview</arg>
</vmArgs>
<linuxConfig>
<generateAppImage>false</generateAppImage>
<generateDeb>true</generateDeb>
<generateRpm>false</generateRpm>
<wrapJar>true</wrapJar>
</linuxConfig>
</configuration> However, when I configure JP so that it uses the FAT JAR, it will package the Error: Unable to initialize main class com.simtechdata.Main
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException But when I run the fat jar like this: java --enable-preview -jar target/iGet-jar-with-dependencies.jar It runs fine. So it apparently is not executing the fat jar properly or something else is going on that I don't understand. And here is the POM config that gives that behavior: <configuration>
<mainClass>${mainClass}</mainClass>
<bundleJre>true</bundleJre>
<runnableJar>${build.directory}/${artifactId}-jar-with-dependencies.jar</runnableJar>
<copyDependencies>false</copyDependencies>
<platform>linux</platform>
<name>iget</name>
<vmArgs>
<arg>--enable-preview</arg>
</vmArgs>
<linuxConfig>
<generateAppImage>false</generateAppImage>
<generateDeb>true</generateDeb>
<generateRpm>false</generateRpm>
<wrapJar>true</wrapJar>
</linuxConfig>
</configuration> And all of that is with version 1.7.5 As soon as I switch to 1.7.6-SNAPSHOT, it won't even compile the deb file and it throws the error I gave you in the zip file in my previous message. |
You should use the specific snapshot version: |
Yes, this error is caused by an incomplete generated JRE. |
@fvarrui And I'm going to assume for the moment, that jdeps is used to compile Java code whether or not the project has any module files? Cause mine does not have a module-info.java file (it is not modular). |
Let me explain:
C:\Users\fvarrui>java --list-modules
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
For example, you can see here my jar, containing my compiled classes:
and its dependencies, all copied into
then you run C:\Users\fvarrui\GitHub\HelloWorldMaven>jdeps -q --multi-release 21 --ignore-missing-deps --print-module-deps --add-modules=ALL-MODULE-PATH --module-path=C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven-1.0.0-runnable.jar;C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven\libs
java.base,java.desktop,java.logging,java.security.jgss,java.xml.crypto and it'll find all necessary modules:
Therefore, now you can pass the modules found by C:\Users\fvarrui\GitHub\HelloWorldMaven>jlink "--module-path=C:\Program Files\GraalVM\graalvm-community-openjdk-21.0.2+13.1\jmods" --add-modules java.base,java.desktop,java.logging,java.security.jgss,java.xml.crypto --output C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven\jre --no-header-files --no-man-pages --strip-debug Finally, to check that all worked fine, you can run C:\Users\fvarrui\GitHub\HelloWorldMaven>C:\Users\fvarrui\GitHub\HelloWorldMaven\target\HelloWorldMaven\jre\bin\java --list-modules
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected] And voila! Your JRE only includes those specific modules and the modules they depend on. I think that if you include a I hope this helps! |
@fvarrui |
I think it's not a replacement, but a encapsulation improvement for better practices. A JAR can be modularized just including a Sorry for my late reply! |
I'm submitting a…
Short description of the issue/suggestion:
When following your example of creating a package using a fat jar, JavaPackager seems to not actually use that jar when it builds the package.
So here are my POM settings:
The fat jar is created with maven-assembly plugin.
The build completes without any errors. But when I run the program and it gets to where it is needing to access a dependency, it throws an error saying it cannot find the dependency. HOWEVER, when I run the fat jar with
java -jar
, everything works fine.So I looked more closely at the feedback during the build process and I noticed right after the fat jar is built, JavaPackager takes over, but it doesn't actually use the fat jar, rather, it makes its own jar instead.
In this text from the build feedback, notice that the fat jar is indeed listed in the
runnableJar
setting:But then what comes next, is that it shows adding assets and resources, then it goes straight into building it's own jar called
iGet-2.0.0-runnable.jar
where I would have assumed that it would just use the fat jar that I specified. But the jar that it builds doesn't have the dependencies of course because you said to disable that when using a fat jar.All throughout the rest of the build, it only ever uses the jar that it built and the only mention at all of the fat jar is in the config that it spits out at the top.
Notice its using the runnable jar when it creates the final program and not the jar-with-dependencies as it should be using.
I've managed to get what I needed by just letting JP build the package without the fat jar, but I wanted to bring this up because it might be something you want to address or explain to me what I did wrong?
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: