aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore9
-rw-r--r--build.bat56
-rwxr-xr-xbuild.sh61
-rw-r--r--lib/junit-platform-console-standalone-6.1.1.jarbin0 -> 2996922 bytes
-rw-r--r--run.bat4
-rw-r--r--run.sh4
6 files changed, 124 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index b63bf17..774d6b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,12 @@
1# Ignore compiled Java bytecode 1# Ignore compiled Java bytecode
2bin/ 2bin/
3stage/
4dist/
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
11Thumbs.db 9Thumbs.db
12 10
13# Optional: Ignore environment properties if they hold local secrets 11config.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
2setlocal enabledelayedexpansion
3
4echo === 1. Cleaning Workspace ===
5if exist bin rmdir /s /q bin
6if exist bin-test rmdir /s /q bin-test
7if exist fat-stage rmdir /s /q fat-stage
8if exist app.jar del app.jar
9mkdir bin
10mkdir bin-test
11mkdir fat-stage
12
13echo === 2. Compiling Production Code ===
14javac -d bin -cp "lib/*" src/com/example/App.java
15if %errorlevel% neq 0 exit /b %errorlevel%
16
17echo === 3. Compiling Test Code ===
18javac -d bin-test -cp "bin;lib/*" test/com/example/AppTest.java
19if %errorlevel% neq 0 exit /b %errorlevel%
20
21echo === 4. Running Automated Tests ===
22set "JUNIT_JAR="
23for %%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)
25
26java -jar "!JUNIT_JAR!" --classpath "bin;bin-test;lib/*" --scan-class-path
27if %errorlevel% neq 0 (
28 echo ❌ Tests failed! Aborting build package.
29 exit /b %errorlevel%
30)
31echo ✅ Tests passed successfully!
32
33echo === 5. Extracting Dependencies for Fat JAR ===
34cd fat-stage
35for %%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)
42if exist META-INF rmdir /s /q META-INF
43cd ..
44
45echo === 6. Merging Assets into Fat JAR ===
46xcopy /e /q /y bin\* fat-stage\
47jar cfm app.jar manifest.txt -C fat-stage/ .
48if %errorlevel% neq 0 exit /b %errorlevel%
49
50rmdir /s /q fat-stage
51echo ======================================
52echo 🎉 Fat JAR Created! Run it anywhere using:
53echo java -jar app.jar
54echo ======================================
55pause
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
2set -e
3
4echo "=== 1. Cleaning Workspace ==="
5rm -rf bin stage
6mkdir bin bin/classes bin/test-classes stage
7
8echo "=== 2. Compiling Production Code ==="
9javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java
10
11echo "=== 3. Compiling Test Code ==="
12javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java
13
14echo "=== 4. Running Automated Tests ==="
15JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1)
16if [ -z "$JUNIT_JAR" ]; then
17 echo "JUnit jar missing."
18 exit 1
19fi
20
21set +e
22java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath
23TEST_STATUS=$?
24set -e
25
26if [ $TEST_STATUS -ne 0 ]; then
27 echo "❌ Tests failed! Aborting build package."
28 exit 1
29fi
30echo "✅ Tests passed successfully!"
31
32echo "=== 5. Extracting Dependencies for Fat JAR ==="
33cd stage
34for 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
44done
45# Clean up extracted manifest directories to prevent conflicts
46rm -rf META-INF
47cd ..
48
49echo "=== 6. Merging Assets into Fat JAR ==="
50# Copy your own compiled production classes into the staging folder
51cp -r bin/* stage/
52
53# Package everything in the staging area into the final JAR
54jar cfe dist/app.jar com.example.App -C stage/classes/ .
55
56# Clean up staging area
57rm -rf stage
58echo "======================================"
59echo "🎉 Fat JAR Created! Run it anywhere using:"
60echo "java -jar app.jar"
61echo "======================================"
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
diff --git a/run.bat b/run.bat
index 6d3f6e6..8480652 100644
--- a/run.bat
+++ b/run.bat
@@ -4,12 +4,12 @@ rmdir /s /q bin
4mkdir bin 4mkdir bin
5 5
6:: compile source files and include libraries 6:: compile source files and include libraries
7javac -d bin -cp "lib/*" src/main/java/com/example/App.java 7javac -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
10if %errorlevel% equ 0 ( 10if %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)
diff --git a/run.sh b/run.sh
index d50ae4d..55f1094 100644
--- a/run.sh
+++ b/run.sh
@@ -4,9 +4,9 @@
4rm -rf bin && mkdir bin 4rm -rf bin && mkdir bin
5 5
6# run the app if compilation succeeded 6# run the app if compilation succeeded
7if javac -d bin -cp "lib/*" src/main/java/com/example/App.java; then 7if 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
10else 10else
11 echo "Compilation failed." 11 echo "Compilation failed."
12fi 12fi