From 325d40e9bcc54d3389450fb951c873ffb466bb64 Mon Sep 17 00:00:00 2001 From: Kostya Date: Sat, 25 Jul 2026 14:59:02 +0000 Subject: fat jar build --- build.bat | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 build.bat (limited to 'build.bat') diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..e1f3d72 --- /dev/null +++ b/build.bat @@ -0,0 +1,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 + -- cgit v1.2.3