From 325d40e9bcc54d3389450fb951c873ffb466bb64 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sat, 25 Jul 2026 14:59:02 +0000 Subject: fat jar build --- build.sh | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 build.sh (limited to 'build.sh') diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ca768c4 --- /dev/null +++ b/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e + +echo "=== 1. Cleaning Workspace ===" +rm -rf bin stage +mkdir bin bin/classes bin/test-classes stage + +echo "=== 2. Compiling Production Code ===" +javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java + +echo "=== 3. Compiling Test Code ===" +javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java + +echo "=== 4. Running Automated Tests ===" +JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1) +if [ -z "$JUNIT_JAR" ]; then + echo "JUnit jar missing." + exit 1 +fi + +set +e +java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath +TEST_STATUS=$? +set -e + +if [ $TEST_STATUS -ne 0 ]; then + echo "❌ Tests failed! Aborting build package." + exit 1 +fi +echo "✅ Tests passed successfully!" + +echo "=== 5. Extracting Dependencies for Fat JAR ===" +cd stage +for jarfile in ../lib/*.jar; do + echo "$jarfile" + # Skip the JUnit jar so we don't bloat production code + if [[ "$jarfile" == *"junit-platform-console-standalone"* ]]; then + continue + fi + if [ -f "$jarfile" ]; then + echo "Extracting: $(basename "$jarfile")" + jar -xf "$jarfile" + fi +done +# Clean up extracted manifest directories to prevent conflicts +rm -rf META-INF +cd .. + +echo "=== 6. Merging Assets into Fat JAR ===" +# Copy your own compiled production classes into the staging folder +cp -r bin/* stage/ + +# Package everything in the staging area into the final JAR +jar cfe dist/app.jar com.example.App -C stage/classes/ . + +# Clean up staging area +rm -rf stage +echo "======================================" +echo "🎉 Fat JAR Created! Run it anywhere using:" +echo "java -jar app.jar" +echo "======================================" -- cgit v1.2.3