diff options
| author | Kostya <mail@sartin.in> | 2026-07-26 18:29:52 +0300 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-07-26 18:29:52 +0300 |
| commit | b9c9c4f21cb8b40b240593e240754d5bce54a023 (patch) | |
| tree | c3390a0c37332b0bf7b2049f3de13cd1f900629d /build.sh | |
| parent | 325d40e9bcc54d3389450fb951c873ffb466bb64 (diff) | |
| download | java-bootstrap-master.tar.gz java-bootstrap-master.tar.xz java-bootstrap-master.zip | |
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 48 |
1 files changed, 24 insertions, 24 deletions
| @@ -3,23 +3,26 @@ set -e | |||
| 3 | 3 | ||
| 4 | echo "=== 1. Cleaning Workspace ===" | 4 | echo "=== 1. Cleaning Workspace ===" |
| 5 | rm -rf bin stage | 5 | rm -rf bin stage |
| 6 | mkdir bin bin/classes bin/test-classes stage | 6 | mkdir -p bin/classes bin/test-classes stage dist # dist was never created |
| 7 | 7 | ||
| 8 | echo "=== 2. Compiling Production Code ===" | 8 | echo "=== 2. Compiling Production Code ===" |
| 9 | javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java | 9 | javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java') |
| 10 | 10 | ||
| 11 | echo "=== 3. Compiling Test Code ===" | 11 | echo "=== 3. Compiling Test Code ===" |
| 12 | javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java | 12 | # prod classes are in bin/classes, not bin |
| 13 | javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java') | ||
| 13 | 14 | ||
| 14 | echo "=== 4. Running Automated Tests ===" | 15 | echo "=== 4. Running Automated Tests ===" |
| 15 | JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1) | 16 | JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1) |
| 16 | if [ -z "$JUNIT_JAR" ]; then | 17 | if [ -z "$JUNIT_JAR" ]; then |
| 17 | echo "JUnit jar missing." | 18 | echo "JUnit jar missing." |
| 18 | exit 1 | 19 | exit 1 |
| 19 | fi | 20 | fi |
| 20 | 21 | ||
| 21 | set +e | 22 | set +e |
| 22 | java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath | 23 | java -jar "$JUNIT_JAR" execute \ |
| 24 | -cp "bin/classes:bin/test-classes:lib/*" \ | ||
| 25 | --scan-classpath | ||
| 23 | TEST_STATUS=$? | 26 | TEST_STATUS=$? |
| 24 | set -e | 27 | set -e |
| 25 | 28 | ||
| @@ -32,30 +35,27 @@ echo "✅ Tests passed successfully!" | |||
| 32 | echo "=== 5. Extracting Dependencies for Fat JAR ===" | 35 | echo "=== 5. Extracting Dependencies for Fat JAR ===" |
| 33 | cd stage | 36 | cd stage |
| 34 | for jarfile in ../lib/*.jar; do | 37 | for jarfile in ../lib/*.jar; do |
| 35 | echo "$jarfile" | 38 | [ -f "$jarfile" ] || continue |
| 36 | # Skip the JUnit jar so we don't bloat production code | 39 | case "$(basename "$jarfile")" in |
| 37 | if [[ "$jarfile" == *"junit-platform-console-standalone"* ]]; then | 40 | junit-platform-console-standalone-*) continue ;; |
| 38 | continue | 41 | esac |
| 39 | fi | 42 | echo "Extracting: $(basename "$jarfile")" |
| 40 | if [ -f "$jarfile" ]; then | 43 | jar -xf "$jarfile" |
| 41 | echo "Extracting: $(basename "$jarfile")" | ||
| 42 | jar -xf "$jarfile" | ||
| 43 | fi | ||
| 44 | done | 44 | done |
| 45 | # Clean up extracted manifest directories to prevent conflicts | 45 | |
| 46 | rm -rf META-INF | 46 | # Strip signatures + manifests (they break repacking), but KEEP |
| 47 | # META-INF/services so ServiceLoader-based deps still work at runtime. | ||
| 48 | find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true | ||
| 47 | cd .. | 49 | cd .. |
| 48 | 50 | ||
| 49 | echo "=== 6. Merging Assets into Fat JAR ===" | 51 | echo "=== 6. Merging Assets into Fat JAR ===" |
| 50 | # Copy your own compiled production classes into the staging folder | 52 | # Merge YOUR production classes on top of the extracted deps |
| 51 | cp -r bin/* stage/ | 53 | cp -r bin/classes/. stage/ |
| 52 | 54 | # Package the whole tree (deps + your classes), not just stage/classes | |
| 53 | # Package everything in the staging area into the final JAR | 55 | jar cfe dist/app.jar com.example.App -C stage . |
| 54 | jar cfe dist/app.jar com.example.App -C stage/classes/ . | ||
| 55 | 56 | ||
| 56 | # Clean up staging area | ||
| 57 | rm -rf stage | 57 | rm -rf stage |
| 58 | echo "======================================" | 58 | echo "======================================" |
| 59 | echo "🎉 Fat JAR Created! Run it anywhere using:" | 59 | echo "🎉 Fat JAR Created! Run it with:" |
| 60 | echo "java -jar app.jar" | 60 | echo "java -jar dist/app.jar" |
| 61 | echo "======================================" | 61 | echo "======================================" |