Description
I'm submitting a…
- bug report
- feature request
- other
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:
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>${javapackager}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<mainClass>${mainClass}</mainClass>
<bundleJre>true</bundleJre>
<runnableJar>${build.directory}/${artifactId}-${project.version}.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>
</execution>
</executions>
</plugin>
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:
[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
[INFO]
[INFO] --- javapackager:1.7.5:package (default) @ iGet ---
[INFO] Using packager io.github.fvarrui.javapackager.packagers.LinuxPackager
[INFO] Creating app ...
[INFO] Initializing packager ...
[INFO] PackagerSettings [
outputDirectory=/home/michael/java/iGet/target,
licenseFile=null,
iconFile=null,
generateInstaller=true,
forceInstaller=false,
mainClass=com.simtechdata.Main,
name=iget,
displayName=iGet,
version=2.0.0,
description=A program that downloads Instagram Reels and Youtube videos,
url=null,
administratorRequired=false,
organizationName=ACME,
organizationUrl=,
organizationEmail=null,
bundleJre=true,
customizedJre=true,
jrePath=null,
jdkPath=/home/michael/.sdkman/candidates/java/22.0.1-graal,
additionalResources=[],
modules=[],
additionalModules=[],
platform=linux,
envPath=null,
vmArgs=[--enable-preview],
runnableJar=/home/michael/java/iGet/target/iGet-2.0.0.jar-with-dependencies.jar,
^ This is correct and the file exists
copyDependencies=false,
jreDirectoryName=jre,
winConfig=null,
linuxConfig=LinuxConfig [categories=[Utility],
generateDeb=true,
generateRpm=false,
generateAppImage=false,
pngFile=null,
wrapJar=true,
installationPath=/opt],
macConfig=null,
createTarball=false,
tarballName=null,
createZipball=false,
zipballName=null,
extra=null,
useResourcesAsWorkingDir=true,
assetsDir=/home/michael/java/iGet/assets,
classpath=null,
jreMinVersion=null,
manifest=null,
additionalModulePaths=[],
fileAssociations=[],
packagingJdk=/home/michael/.sdkman/candidates/java/22.0.1-graal,
scripts=Scripts [bootstrap=null,
preInstall=null,
postInstall=null],
arch=x64,
templates=[Template [name=windows/iss.vtl,
bom=true]]]
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.
[INFO] Packager initialized!
[INFO]
[INFO] Creating app structure ...
[INFO] App folder created: /home/michael/java/iGet/target/iget
[INFO] Assets folder created: /home/michael/java/iGet/target/assets
[INFO] App structure created!
[INFO]
[INFO] Resolving resources ...
[INFO] Trying to resolve license from POM ...
[INFO] License not resolved!
[INFO]
[WARNING] No license file specified
[INFO] Copying resource [/linux/default-icon.png] to file [/home/michael/java/iGet/target/assets/iget.png]
[INFO] Icon file resolved: /home/michael/java/iGet/target/assets/iget.png
[INFO] Effective additional resources [/home/michael/java/iGet/target/assets/iget.png]
[INFO] Resources resolved!
[INFO]
[INFO] Copying additional resources
[INFO] Copying file [/home/michael/java/iGet/target/assets/iget.png] to folder [/home/michael/java/iGet/target/iget]
[INFO] Executing command: /bin/sh -c cd '/home/michael/java/iGet/.' && 'cp' /home/michael/java/iGet/target/assets/iget.png /home/michael/java/iGet/target/iget/iget.png
[INFO] All additional resources copied!
[INFO]
[INFO] Copying all dependencies ...
[INFO] Dependencies copied to null!
[INFO]
[INFO] Creating runnable JAR...
[INFO] Building jar: /home/michael/java/iGet/target/iGet-2.0.0-runnable.jar
[INFO] Runnable jar created in /home/michael/java/iGet/target/iGet-2.0.0-runnable.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.
[INFO] Creating GNU/Linux executable ...
[INFO] Rendering desktop file to /home/michael/java/iGet/target/assets/iget.desktop
[INFO] Startup script generated in /home/michael/java/iGet/target/assets/startup.sh
[INFO] Concatenating files [/home/michael/java/iGet/target/assets/startup.sh,/home/michael/java/iGet/target/iGet-2.0.0-runnable.jar] into file [/home/michael/java/iGet/target/iget/iget]
[INFO] GNU/Linux executable created in /home/michael/java/iGet/target/iget/iget!
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:
- JavaPackager version: 1.7.5
- OS version: Ubuntu 22.0.4
- JDK version: 22
- Build tool:
- Maven
- Gradle