diff options
| author | Kostya <mail@sartin.in> | 2026-07-25 14:59:02 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-07-25 14:59:02 +0000 |
| commit | 325d40e9bcc54d3389450fb951c873ffb466bb64 (patch) | |
| tree | 1e67e8fc8caed8ccbca47df367706312c4ec581b | |
| parent | 0290b3ea1c810f21ce29efc3b7f24969aeeba9c4 (diff) | |
| download | java-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.tar.gz java-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.tar.xz java-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.zip | |
fat jar build
| -rw-r--r-- | .gitignore | 9 | ||||
| -rw-r--r-- | build.bat | 56 | ||||
| -rwxr-xr-x | build.sh | 61 | ||||
| -rw-r--r-- | lib/junit-platform-console-standalone-6.1.1.jar | bin | 0 -> 2996922 bytes | |||
| -rw-r--r-- | run.bat | 4 | ||||
| -rw-r--r-- | run.sh | 4 |
6 files changed, 124 insertions, 10 deletions
| @@ -1,15 +1,12 @@ | |||
| 1 | # Ignore compiled Java bytecode | 1 | # Ignore compiled Java bytecode |
| 2 | bin/ | 2 | bin/ |
| 3 | stage/ | ||
| 4 | dist/ | ||
| 3 | *.class | 5 | *.class |
| 4 | 6 | ||
| 5 | # Ignore packaged binaries | ||
| 6 | *.jar | ||
| 7 | *.war | ||
| 8 | |||
| 9 | # Ignore OS-specific files | 7 | # Ignore OS-specific files |
| 10 | .DS_Store | 8 | .DS_Store |
| 11 | Thumbs.db | 9 | Thumbs.db |
| 12 | 10 | ||
| 13 | # Optional: Ignore environment properties if they hold local secrets | 11 | config.properties |
| 14 | # config.properties | ||
| 15 | 12 | ||
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 | |||
diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ca768c4 --- /dev/null +++ b/build.sh | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | set -e | ||
| 3 | |||
| 4 | echo "=== 1. Cleaning Workspace ===" | ||
| 5 | rm -rf bin stage | ||
| 6 | mkdir bin bin/classes bin/test-classes stage | ||
| 7 | |||
| 8 | echo "=== 2. Compiling Production Code ===" | ||
| 9 | javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java | ||
| 10 | |||
| 11 | echo "=== 3. Compiling Test Code ===" | ||
| 12 | javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java | ||
| 13 | |||
| 14 | echo "=== 4. Running Automated Tests ===" | ||
| 15 | JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1) | ||
| 16 | if [ -z "$JUNIT_JAR" ]; then | ||
| 17 | echo "JUnit jar missing." | ||
| 18 | exit 1 | ||
| 19 | fi | ||
| 20 | |||
| 21 | set +e | ||
| 22 | java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath | ||
| 23 | TEST_STATUS=$? | ||
| 24 | set -e | ||
| 25 | |||
| 26 | if [ $TEST_STATUS -ne 0 ]; then | ||
| 27 | echo "❌ Tests failed! Aborting build package." | ||
| 28 | exit 1 | ||
| 29 | fi | ||
| 30 | echo "✅ Tests passed successfully!" | ||
| 31 | |||
| 32 | echo "=== 5. Extracting Dependencies for Fat JAR ===" | ||
| 33 | cd stage | ||
| 34 | for jarfile in ../lib/*.jar; do | ||
| 35 | echo "$jarfile" | ||
| 36 | # Skip the JUnit jar so we don't bloat production code | ||
| 37 | if [[ "$jarfile" == *"junit-platform-console-standalone"* ]]; then | ||
| 38 | continue | ||
| 39 | fi | ||
| 40 | if [ -f "$jarfile" ]; then | ||
| 41 | echo "Extracting: $(basename "$jarfile")" | ||
| 42 | jar -xf "$jarfile" | ||
| 43 | fi | ||
| 44 | done | ||
| 45 | # Clean up extracted manifest directories to prevent conflicts | ||
| 46 | rm -rf META-INF | ||
| 47 | cd .. | ||
| 48 | |||
| 49 | echo "=== 6. Merging Assets into Fat JAR ===" | ||
| 50 | # Copy your own compiled production classes into the staging folder | ||
| 51 | cp -r bin/* stage/ | ||
| 52 | |||
| 53 | # Package everything in the staging area into the final JAR | ||
| 54 | jar cfe dist/app.jar com.example.App -C stage/classes/ . | ||
| 55 | |||
| 56 | # Clean up staging area | ||
| 57 | rm -rf stage | ||
| 58 | echo "======================================" | ||
| 59 | echo "🎉 Fat JAR Created! Run it anywhere using:" | ||
| 60 | echo "java -jar app.jar" | ||
| 61 | echo "======================================" | ||
diff --git a/lib/junit-platform-console-standalone-6.1.1.jar b/lib/junit-platform-console-standalone-6.1.1.jar new file mode 100644 index 0000000..ce038a5 --- /dev/null +++ b/lib/junit-platform-console-standalone-6.1.1.jar | |||
| Binary files differ | |||
| @@ -4,12 +4,12 @@ rmdir /s /q bin | |||
| 4 | mkdir bin | 4 | mkdir bin |
| 5 | 5 | ||
| 6 | :: compile source files and include libraries | 6 | :: compile source files and include libraries |
| 7 | javac -d bin -cp "lib/*" src/main/java/com/example/App.java | 7 | javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java |
| 8 | 8 | ||
| 9 | :: run the application if compilation succeeded | 9 | :: run the application if compilation succeeded |
| 10 | if %errorlevel% equ 0 ( | 10 | if %errorlevel% equ 0 ( |
| 11 | echo --- Running Application --- | 11 | echo --- Running Application --- |
| 12 | java -cp "bin;lib/*" com.example.App | 12 | java -cp "bin/classes;lib/*" com.example.App |
| 13 | ) else ( | 13 | ) else ( |
| 14 | echo Compilation failed. | 14 | echo Compilation failed. |
| 15 | ) | 15 | ) |
| @@ -4,9 +4,9 @@ | |||
| 4 | rm -rf bin && mkdir bin | 4 | rm -rf bin && mkdir bin |
| 5 | 5 | ||
| 6 | # run the app if compilation succeeded | 6 | # run the app if compilation succeeded |
| 7 | if javac -d bin -cp "lib/*" src/main/java/com/example/App.java; then | 7 | if javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java; then |
| 8 | echo "--- Running Application ---" | 8 | echo "--- Running Application ---" |
| 9 | java -cp "bin:lib/*" com.example.App | 9 | java -cp "bin/classes:lib/*" com.example.App |
| 10 | else | 10 | else |
| 11 | echo "Compilation failed." | 11 | echo "Compilation failed." |
| 12 | fi | 12 | fi |