aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya <mail@sartin.in>2026-07-26 18:29:52 +0300
committerKostya <mail@sartin.in>2026-07-26 18:29:52 +0300
commitb9c9c4f21cb8b40b240593e240754d5bce54a023 (patch)
treec3390a0c37332b0bf7b2049f3de13cd1f900629d
parent325d40e9bcc54d3389450fb951c873ffb466bb64 (diff)
downloadjava-bootstrap-b9c9c4f21cb8b40b240593e240754d5bce54a023.tar.gz
java-bootstrap-b9c9c4f21cb8b40b240593e240754d5bce54a023.tar.xz
java-bootstrap-b9c9c4f21cb8b40b240593e240754d5bce54a023.zip
fix build scriptsHEADmaster
-rw-r--r--build.bat58
-rwxr-xr-xbuild.sh48
2 files changed, 61 insertions, 45 deletions
diff --git a/build.bat b/build.bat
index e1f3d72..eb6b460 100644
--- a/build.bat
+++ b/build.bat
@@ -2,20 +2,22 @@
2setlocal enabledelayedexpansion 2setlocal enabledelayedexpansion
3 3
4echo === 1. Cleaning Workspace === 4echo === 1. Cleaning Workspace ===
5if exist bin rmdir /s /q bin 5if exist bin rmdir /s /q bin
6if exist bin-test rmdir /s /q bin-test 6if exist stage rmdir /s /q stage
7if exist fat-stage rmdir /s /q fat-stage 7if exist dist rmdir /s /q dist
8if exist app.jar del app.jar 8mkdir bin\classes
9mkdir bin 9mkdir bin\test-classes
10mkdir bin-test 10mkdir stage
11mkdir fat-stage 11mkdir dist
12 12
13echo === 2. Compiling Production Code === 13echo === 2. Compiling Production Code ===
14javac -d bin -cp "lib/*" src/com/example/App.java 14dir /s /b src\main\java\*.java > sources.txt
15javac -d bin\classes -cp "lib/*" @sources.txt
15if %errorlevel% neq 0 exit /b %errorlevel% 16if %errorlevel% neq 0 exit /b %errorlevel%
16 17
17echo === 3. Compiling Test Code === 18echo === 3. Compiling Test Code ===
18javac -d bin-test -cp "bin;lib/*" test/com/example/AppTest.java 19dir /s /b src\test\java\*.java > test-sources.txt
20javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt
19if %errorlevel% neq 0 exit /b %errorlevel% 21if %errorlevel% neq 0 exit /b %errorlevel%
20 22
21echo === 4. Running Automated Tests === 23echo === 4. Running Automated Tests ===
@@ -23,34 +25,48 @@ set "JUNIT_JAR="
23for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" 25for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f"
24if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) 26if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1)
25 27
26java -jar "!JUNIT_JAR!" --classpath "bin;bin-test;lib/*" --scan-class-path 28rem JUnit's --class-path does NOT expand lib\* -> build it explicitly
29set "TEST_CP=bin\classes;bin\test-classes"
30for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j"
31
32java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath
27if %errorlevel% neq 0 ( 33if %errorlevel% neq 0 (
28 echo Tests failed! Aborting build package. 34 echo [X] Tests failed! Aborting build package.
29 exit /b %errorlevel% 35 exit /b %errorlevel%
30) 36)
31echo Tests passed successfully! 37echo [OK] Tests passed successfully!
32 38
33echo === 5. Extracting Dependencies for Fat JAR === 39echo === 5. Extracting Dependencies for Fat JAR ===
34cd fat-stage 40cd stage
35for %%j in (..\lib\*.jar) do ( 41for %%j in (..\lib\*.jar) do (
36 echo %%j | findstr /i "junit-platform-console-standalone" >nul 42 echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul
37 if errorlevel 1 ( 43 if errorlevel 1 (
38 echo Extracting: %%~nxj 44 echo Extracting: %%~nxj
39 jar -xf "%%j" 45 jar -xf "%%j"
40 ) 46 )
41) 47)
42if exist META-INF rmdir /s /q META-INF 48
49rem Strip signatures + manifests (they break repacking) but KEEP
50rem META-INF\services so ServiceLoader-based deps still work at runtime.
51if exist META-INF (
52 del /s /q META-INF\*.SF >nul 2>&1
53 del /s /q META-INF\*.RSA >nul 2>&1
54 del /s /q META-INF\*.DSA >nul 2>&1
55 del /q META-INF\MANIFEST.MF >nul 2>&1
56)
43cd .. 57cd ..
44 58
45echo === 6. Merging Assets into Fat JAR === 59echo === 6. Merging Assets into Fat JAR ===
46xcopy /e /q /y bin\* fat-stage\ 60rem Merge ONLY production classes on top of the extracted deps
47jar cfm app.jar manifest.txt -C fat-stage/ . 61xcopy /e /q /y /i bin\classes\* stage\ >nul
62rem Package the whole tree (deps + your classes), not just stage\classes
63jar cfe dist/app.jar com.example.App -C stage .
48if %errorlevel% neq 0 exit /b %errorlevel% 64if %errorlevel% neq 0 exit /b %errorlevel%
49 65
50rmdir /s /q fat-stage 66del sources.txt test-sources.txt >nul 2>&1
67rmdir /s /q stage
51echo ====================================== 68echo ======================================
52echo 🎉 Fat JAR Created! Run it anywhere using: 69echo Fat JAR Created! Run it with:
53echo java -jar app.jar 70echo java -jar dist/app.jar
54echo ====================================== 71echo ======================================
55pause 72pause
56
diff --git a/build.sh b/build.sh
index ca768c4..6fdf7e1 100755
--- a/build.sh
+++ b/build.sh
@@ -3,23 +3,26 @@ set -e
3 3
4echo "=== 1. Cleaning Workspace ===" 4echo "=== 1. Cleaning Workspace ==="
5rm -rf bin stage 5rm -rf bin stage
6mkdir bin bin/classes bin/test-classes stage 6mkdir -p bin/classes bin/test-classes stage dist # dist was never created
7 7
8echo "=== 2. Compiling Production Code ===" 8echo "=== 2. Compiling Production Code ==="
9javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java 9javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java')
10 10
11echo "=== 3. Compiling Test Code ===" 11echo "=== 3. Compiling Test Code ==="
12javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java 12# prod classes are in bin/classes, not bin
13javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java')
13 14
14echo "=== 4. Running Automated Tests ===" 15echo "=== 4. Running Automated Tests ==="
15JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1) 16JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1)
16if [ -z "$JUNIT_JAR" ]; then 17if [ -z "$JUNIT_JAR" ]; then
17 echo "JUnit jar missing." 18 echo "JUnit jar missing."
18 exit 1 19 exit 1
19fi 20fi
20 21
21set +e 22set +e
22java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath 23java -jar "$JUNIT_JAR" execute \
24 -cp "bin/classes:bin/test-classes:lib/*" \
25 --scan-classpath
23TEST_STATUS=$? 26TEST_STATUS=$?
24set -e 27set -e
25 28
@@ -32,30 +35,27 @@ echo "✅ Tests passed successfully!"
32echo "=== 5. Extracting Dependencies for Fat JAR ===" 35echo "=== 5. Extracting Dependencies for Fat JAR ==="
33cd stage 36cd stage
34for jarfile in ../lib/*.jar; do 37for 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
44done 44done
45# Clean up extracted manifest directories to prevent conflicts 45
46rm -rf META-INF 46# Strip signatures + manifests (they break repacking), but KEEP
47# META-INF/services so ServiceLoader-based deps still work at runtime.
48find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true
47cd .. 49cd ..
48 50
49echo "=== 6. Merging Assets into Fat JAR ===" 51echo "=== 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
51cp -r bin/* stage/ 53cp -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 55jar cfe dist/app.jar com.example.App -C stage .
54jar cfe dist/app.jar com.example.App -C stage/classes/ .
55 56
56# Clean up staging area
57rm -rf stage 57rm -rf stage
58echo "======================================" 58echo "======================================"
59echo "🎉 Fat JAR Created! Run it anywhere using:" 59echo "🎉 Fat JAR Created! Run it with:"
60echo "java -jar app.jar" 60echo "java -jar dist/app.jar"
61echo "======================================" 61echo "======================================"