1+ #! /bin/sh
2+
3+ set -e
4+
5+ # Configuration
6+ PACKAGE_NAME=" JavaAppTemplate-linux"
7+ JRE_DIR=" jre-linux"
8+ ADOPTIUM_BASE_URL=" https://api.adoptium.net/v3/binary/latest/25/ga"
9+
10+ # Clean up any previous builds
11+ rm -rf ${PACKAGE_NAME}
12+ rm -rf ${JRE_DIR}
13+ rm -f ${PACKAGE_NAME} .tar.xz
14+ rm -f ${PACKAGE_NAME} .tar.gz
15+
16+ # Build the application using Gradle
17+ echo " Building application..."
18+ ./gradlew build
19+
20+ # Download JRE for Linux from Eclipse Adoptium
21+ echo " Downloading JRE for Linux..."
22+ mkdir -p ${JRE_DIR}
23+ curl -L " ${ADOPTIUM_BASE_URL} /linux/x64/jre/hotspot/normal/eclipse?project=jdk" -o ${JRE_DIR} /jre-linux.tar.gz
24+
25+ # Extract the downloaded JRE
26+ echo " Extracting JRE..."
27+ cd ${JRE_DIR}
28+ tar -xzf jre-linux.tar.gz
29+ JRE_EXTRACTED=$( ls -d jdk* 2> /dev/null || ls -d jre* 2> /dev/null)
30+ cd ..
31+
32+ # Create package directory structure
33+ echo " Creating package structure..."
34+ mkdir -p ${PACKAGE_NAME}
35+ cp app/build/libs/app-all.jar ${PACKAGE_NAME} /app.jar
36+ cp README.md ${PACKAGE_NAME} /README.txt
37+ cp LICENSE ${PACKAGE_NAME} /LICENSE
38+
39+ # Copy the JRE into the package
40+ echo " Copying JRE into package..."
41+ cp -r ${JRE_DIR} /${JRE_EXTRACTED} ${PACKAGE_NAME} /jre
42+
43+ # Create a shell script that uses the bundled JRE
44+ cat > ${PACKAGE_NAME} /run.sh << 'EOF '
45+ #!/bin/sh
46+
47+ # Get the directory where the script is located
48+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
49+
50+ "${SCRIPT_DIR}/jre/bin/java" -jar "${SCRIPT_DIR}/app.jar"
51+ EOF
52+
53+ # Make the run script executable
54+ chmod +x ${PACKAGE_NAME} /run.sh
55+
56+ # Create the final tar.xz archive with maximum compression
57+ echo " Creating tar.xz archive..."
58+ tar -cJf ${PACKAGE_NAME} .tar.xz ${PACKAGE_NAME} /
59+
60+ # Clean up temporary directories
61+ rm -rf ${PACKAGE_NAME}
62+ rm -rf ${JRE_DIR}
63+
64+ echo " "
65+ echo " ✓ Linux package with bundled JRE created: ${PACKAGE_NAME} .tar.xz"
66+ echo " "
0 commit comments