blob: ca768c4f351fd638bb48e26283ff98df28aabafd (
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
57
58
59
60
61
|
#!/bin/bash
set -e
echo "=== 1. Cleaning Workspace ==="
rm -rf bin stage
mkdir bin bin/classes bin/test-classes stage
echo "=== 2. Compiling Production Code ==="
javac -d bin/classes -cp "lib/*" src/main/java/com/example/App.java
echo "=== 3. Compiling Test Code ==="
javac -d bin/test-classes -cp "bin:lib/*" src/test/java/com/example/AppTest.java
echo "=== 4. Running Automated Tests ==="
JUNIT_JAR=$(find lib/junit-platform-console-standalone-*.jar | head -n 1)
if [ -z "$JUNIT_JAR" ]; then
echo "JUnit jar missing."
exit 1
fi
set +e
java -jar "$JUNIT_JAR" execute -cp "bin:lib/*" --scan-classpath
TEST_STATUS=$?
set -e
if [ $TEST_STATUS -ne 0 ]; then
echo "❌ Tests failed! Aborting build package."
exit 1
fi
echo "✅ Tests passed successfully!"
echo "=== 5. Extracting Dependencies for Fat JAR ==="
cd stage
for jarfile in ../lib/*.jar; do
echo "$jarfile"
# Skip the JUnit jar so we don't bloat production code
if [[ "$jarfile" == *"junit-platform-console-standalone"* ]]; then
continue
fi
if [ -f "$jarfile" ]; then
echo "Extracting: $(basename "$jarfile")"
jar -xf "$jarfile"
fi
done
# Clean up extracted manifest directories to prevent conflicts
rm -rf META-INF
cd ..
echo "=== 6. Merging Assets into Fat JAR ==="
# Copy your own compiled production classes into the staging folder
cp -r bin/* stage/
# Package everything in the staging area into the final JAR
jar cfe dist/app.jar com.example.App -C stage/classes/ .
# Clean up staging area
rm -rf stage
echo "======================================"
echo "🎉 Fat JAR Created! Run it anywhere using:"
echo "java -jar app.jar"
echo "======================================"
|