aboutsummaryrefslogtreecommitdiffstats
path: root/build.bat
blob: e1f3d72a06446b109171784fc958f063dbde809f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@echo off
setlocal enabledelayedexpansion

echo === 1. Cleaning Workspace ===
if exist bin rmdir /s /q bin
if exist bin-test rmdir /s /q bin-test
if exist fat-stage rmdir /s /q fat-stage
if exist app.jar del app.jar
mkdir bin
mkdir bin-test
mkdir fat-stage

echo === 2. Compiling Production Code ===
javac -d bin -cp "lib/*" src/com/example/App.java
if %errorlevel% neq 0 exit /b %errorlevel%

echo === 3. Compiling Test Code ===
javac -d bin-test -cp "bin;lib/*" test/com/example/AppTest.java
if %errorlevel% neq 0 exit /b %errorlevel%

echo === 4. Running Automated Tests ===
set "JUNIT_JAR="
for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f"
if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1)

java -jar "!JUNIT_JAR!" --classpath "bin;bin-test;lib/*" --scan-class-path
if %errorlevel% neq 0 (
    echo ❌ Tests failed! Aborting build package.
    exit /b %errorlevel%
)
echo ✅ Tests passed successfully!

echo === 5. Extracting Dependencies for Fat JAR ===
cd fat-stage
for %%j in (..\lib\*.jar) do (
    echo %%j | findstr /i "junit-platform-console-standalone" >nul
    if errorlevel 1 (
        echo Extracting: %%~nxj
        jar -xf "%%j"
    )
)
if exist META-INF rmdir /s /q META-INF
cd ..

echo === 6. Merging Assets into Fat JAR ===
xcopy /e /q /y bin\* fat-stage\
jar cfm app.jar manifest.txt -C fat-stage/ .
if %errorlevel% neq 0 exit /b %errorlevel%

rmdir /s /q fat-stage
echo ======================================
echo 🎉 Fat JAR Created! Run it anywhere using:
echo java -jar app.jar
echo ======================================
pause