Bundle Java JRE with Linux AppImage to avoid having to install it

This commit is contained in:
Bane Stojkovic
2025-05-29 23:32:27 +02:00
parent cd92464467
commit 185b5da4d5
6 changed files with 129 additions and 25 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>org.diylc</groupId>
<artifactId>diylc-parent</artifactId>
<version>5.5.0</version>
<version>5.6.0</version>
</parent>
<artifactId>diylc-core</artifactId>
@@ -324,5 +324,21 @@
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>5</major>
<minor>6</minor>
<build>0</build>
</versionNumber>
<releaseDate>2025-05-26 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Bundle Java JRE with Linux AppImage to avoid having to install it</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a>
</java.util.Arrays_-ArrayList>
+1 -1
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>org.diylc</groupId>
<artifactId>diylc-parent</artifactId>
<version>5.5.0</version>
<version>5.6.0</version>
</parent>
<artifactId>diylc-library</artifactId>
@@ -1,24 +1,58 @@
#!/bin/bash
#set -x # Enable debug mode
set -x # Enable debug mode
# Get the AppImage directory
if [ -n "$APPDIR" ]; then
HERE="$APPDIR/usr/bin"
JRE_PATH="$APPDIR/usr/lib/jre/bin/java"
JRE_DIR="$APPDIR/usr/lib/jre"
else
HERE="$(cd "$(dirname "$0")" && pwd)"
JRE_PATH="$(dirname "$HERE")/lib/jre/bin/java"
JRE_DIR="$(dirname "$HERE")/lib/jre"
fi
echo "diylc.sh: Running from directory: $HERE"
echo "diylc.sh: Looking for JRE at: $JRE_PATH"
# Use system Java
JAVA="$(which java)"
if [ -z "$JAVA" ] || [ ! -x "$JAVA" ]; then
echo "diylc.sh: ERROR - System Java not found or not executable!"
echo "diylc.sh: Please install Java 17 or later"
# List directory contents for debugging
echo "diylc.sh: Contents of $(dirname "$JRE_PATH"):"
ls -la "$(dirname "$JRE_PATH")"
# Use bundled JRE
if [ ! -f "$JRE_PATH" ]; then
echo "diylc.sh: ERROR - Bundled JRE not found at: $JRE_PATH"
exit 1
fi
echo "diylc.sh: Using system Java: $JAVA"
# Check if we're running from a mounted AppImage
if [[ "$HERE" == /tmp/.mount_* ]]; then
echo "diylc.sh: Running from mounted AppImage"
# Create a temporary directory for the JRE
TEMP_DIR="/tmp/diylc-jre-$$"
mkdir -p "$TEMP_DIR"
# Copy the entire JRE directory to the temporary location
echo "diylc.sh: Copying JRE to temporary location: $TEMP_DIR"
cp -r "$JRE_DIR"/* "$TEMP_DIR/"
chmod -R +x "$TEMP_DIR/bin"
JRE_PATH="$TEMP_DIR/bin/java"
# Clean up the temporary directory on exit
trap 'rm -rf "$TEMP_DIR"' EXIT
fi
# Verify permissions
echo "diylc.sh: Verifying JRE permissions..."
ls -la "$JRE_PATH"
if [ ! -x "$JRE_PATH" ]; then
echo "diylc.sh: ERROR - JRE is not executable at: $JRE_PATH"
echo "diylc.sh: Current permissions: $(ls -l "$JRE_PATH")"
exit 1
fi
echo "diylc.sh: Using JRE: $JRE_PATH"
cd "$HERE"
echo "diylc.sh: Current working directory: $(pwd)"
@@ -26,15 +60,17 @@ echo "diylc.sh: Current working directory: $(pwd)"
# Debug: Print command before execution
echo "diylc.sh: Executing DIYLCStarter with Java"
exec "$JAVA" \
-Xms1024m \
-Xmx4096m \
-cp "$APPDIR/usr/lib/diylc.jar" \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.text=ALL-UNNAMED \
--add-opens java.desktop/java.awt=ALL-UNNAMED \
--add-opens java.desktop/java.awt.font=ALL-UNNAMED \
--add-opens java.desktop/java.awt.geom=ALL-UNNAMED \
-Dorg.diylc.scriptRun=true \
org.diylc.DIYLCStarter "$@"
# Execute Java directly with the command array
exec "$JRE_PATH" \
-Xms1024m \
-Xmx4096m \
-cp "$(dirname "$HERE")/lib/diylc.jar" \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.text=ALL-UNNAMED \
--add-opens java.desktop/java.awt=ALL-UNNAMED \
--add-opens java.desktop/java.awt.font=ALL-UNNAMED \
--add-opens java.desktop/java.awt.geom=ALL-UNNAMED \
-Dorg.diylc.scriptRun=true \
org.diylc.DIYLCStarter "$@"
+55 -3
View File
@@ -7,7 +7,7 @@
<parent>
<groupId>org.diylc</groupId>
<artifactId>diylc-parent</artifactId>
<version>5.5.0</version>
<version>5.6.0</version>
</parent>
<artifactId>diylc-swing</artifactId>
@@ -317,12 +317,49 @@
</properties>
<build>
<plugins>
<!-- Create AppDir structure and copy files -->
<!-- Download and extract JRE -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>download-extract-jre</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Clean old jre folder -->
<delete dir="${jre.dest.linux}" />
<!-- Create folder to hold extracted JRE -->
<mkdir dir="${jre.dest.linux}" />
<!-- Download JRE for Linux -->
<mkdir dir="${project.build.directory}/downloads" />
<get src="${jdk.url.linux}"
dest="${project.build.directory}/downloads/${jdk.archive.linux}"
usetimestamp="true" />
<!-- Extract JRE -->
<untar src="${project.build.directory}/downloads/${jdk.archive.linux}"
dest="${jre.dest.linux}"
compression="gzip" />
<!-- Move files up one level -->
<move todir="${jre.dest.linux}">
<fileset dir="${jre.dest.linux}/jdk-${jdk.version}-jre" />
</move>
<!-- Remove empty top-level folder -->
<delete dir="${jre.dest.linux}/jdk-${jdk.version}-jre" />
</target>
</configuration>
</execution>
<!-- Create AppDir structure and copy files -->
<execution>
<id>create-appdir</id>
<phase>package</phase>
@@ -339,7 +376,22 @@
<!-- Copy app files -->
<copy file="${project.build.directory}/diylc.jar" todir="${appdir.dir}/usr/lib" />
<!-- Copy JRE -->
<copy todir="${appdir.dir}/usr/lib/jre">
<fileset dir="${jre.dest.linux}" />
</copy>
<!-- Make JRE files executable -->
<chmod perm="755">
<fileset dir="${appdir.dir}/usr/lib/jre/bin" includes="**/*" />
</chmod>
<!-- Ensure JRE binaries are executable in the source directory too -->
<chmod perm="755">
<fileset dir="${jre.dest.linux}/bin" includes="**/*" />
</chmod>
<!-- Copy AppImage specific files -->
<copy file="${project.basedir}/deploy/linux/appimage/diylc.sh" tofile="${appdir.dir}/usr/bin/diylc.sh" />
<copy file="${project.basedir}/deploy/linux/appimage/AppRun" tofile="${appdir.dir}/AppRun" />
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>org.diylc</groupId>
<artifactId>diylc-parent</artifactId>
<version>5.5.0</version>
<version>5.6.0</version>
<packaging>pom</packaging>
<name>DIY Layout Creator</name>