#!/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 "======================================"