diff options
Diffstat (limited to 'build.bat')
| -rw-r--r-- | build.bat | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..e1f3d72 --- /dev/null +++ b/build.bat | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | @echo off | ||
| 2 | setlocal enabledelayedexpansion | ||
| 3 | |||
| 4 | echo === 1. Cleaning Workspace === | ||
| 5 | if exist bin rmdir /s /q bin | ||
| 6 | if exist bin-test rmdir /s /q bin-test | ||
| 7 | if exist fat-stage rmdir /s /q fat-stage | ||
| 8 | if exist app.jar del app.jar | ||
| 9 | mkdir bin | ||
| 10 | mkdir bin-test | ||
| 11 | mkdir fat-stage | ||
| 12 | |||
| 13 | echo === 2. Compiling Production Code === | ||
| 14 | javac -d bin -cp "lib/*" src/com/example/App.java | ||
| 15 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 16 | |||
| 17 | echo === 3. Compiling Test Code === | ||
| 18 | javac -d bin-test -cp "bin;lib/*" test/com/example/AppTest.java | ||
| 19 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 20 | |||
| 21 | echo === 4. Running Automated Tests === | ||
| 22 | set "JUNIT_JAR=" | ||
| 23 | for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" | ||
| 24 | if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) | ||
| 25 | |||
| 26 | java -jar "!JUNIT_JAR!" --classpath "bin;bin-test;lib/*" --scan-class-path | ||
| 27 | if %errorlevel% neq 0 ( | ||
| 28 | echo ❌ Tests failed! Aborting build package. | ||
| 29 | exit /b %errorlevel% | ||
| 30 | ) | ||
| 31 | echo ✅ Tests passed successfully! | ||
| 32 | |||
| 33 | echo === 5. Extracting Dependencies for Fat JAR === | ||
| 34 | cd fat-stage | ||
| 35 | for %%j in (..\lib\*.jar) do ( | ||
| 36 | echo %%j | findstr /i "junit-platform-console-standalone" >nul | ||
| 37 | if errorlevel 1 ( | ||
| 38 | echo Extracting: %%~nxj | ||
| 39 | jar -xf "%%j" | ||
| 40 | ) | ||
| 41 | ) | ||
| 42 | if exist META-INF rmdir /s /q META-INF | ||
| 43 | cd .. | ||
| 44 | |||
| 45 | echo === 6. Merging Assets into Fat JAR === | ||
| 46 | xcopy /e /q /y bin\* fat-stage\ | ||
| 47 | jar cfm app.jar manifest.txt -C fat-stage/ . | ||
| 48 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 49 | |||
| 50 | rmdir /s /q fat-stage | ||
| 51 | echo ====================================== | ||
| 52 | echo 🎉 Fat JAR Created! Run it anywhere using: | ||
| 53 | echo java -jar app.jar | ||
| 54 | echo ====================================== | ||
| 55 | pause | ||
| 56 | |||