aboutsummaryrefslogtreecommitdiffstats
path: root/build.bat
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 /build.bat
parent325d40e9bcc54d3389450fb951c873ffb466bb64 (diff)
downloadjava-bootstrap-master.tar.gz
java-bootstrap-master.tar.xz
java-bootstrap-master.zip
fix build scriptsHEADmaster
Diffstat (limited to 'build.bat')
-rw-r--r--build.bat58
1 files changed, 37 insertions, 21 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