aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
diff options
context:
space:
mode:
authorKostya <mail@sartin.in>2026-07-25 14:59:02 +0000
committerKostya <mail@sartin.in>2026-07-25 14:59:02 +0000
commit325d40e9bcc54d3389450fb951c873ffb466bb64 (patch)
tree1e67e8fc8caed8ccbca47df367706312c4ec581b /build.sh
parent0290b3ea1c810f21ce29efc3b7f24969aeeba9c4 (diff)
downloadjava-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.tar.gz
java-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.tar.xz
java-bootstrap-325d40e9bcc54d3389450fb951c873ffb466bb64.zip
fat jar build
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh61
1 files changed, 61 insertions, 0 deletions
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 "======================================"