From c3946151d543f568983f1ba16a963ea7dd4b9055 Mon Sep 17 00:00:00 2001 From: Kostya Date: Thu, 6 Aug 2026 14:42:43 +0000 Subject: template initial commit --- .classpath | 20 +++++++ .gitignore | 12 ++++ .project | 28 +++++++++ README.md | 1 + build.bat | 72 ++++++++++++++++++++++++ build.sh | 61 ++++++++++++++++++++ lib/junit-platform-console-standalone-6.1.1.jar | Bin 0 -> 2996922 bytes run.bat | 16 ++++++ run.sh | 12 ++++ src/confing.properties | 0 src/main/java/com/example/App.java | 7 +++ src/test/java/com/example/AppTest.java | 3 + 12 files changed, 232 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 README.md create mode 100644 build.bat create mode 100755 build.sh create mode 100644 lib/junit-platform-console-standalone-6.1.1.jar create mode 100644 run.bat create mode 100644 run.sh create mode 100644 src/confing.properties create mode 100644 src/main/java/com/example/App.java create mode 100644 src/test/java/com/example/AppTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7f8bc25 --- /dev/null +++ b/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..774d6b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Ignore compiled Java bytecode +bin/ +stage/ +dist/ +*.class + +# Ignore OS-specific files +.DS_Store +Thumbs.db + +config.properties + diff --git a/.project b/.project new file mode 100644 index 0000000..c3b90e2 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + App + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + + + 1784965956299 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..091c160 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +New java project bootstrap diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..eb6b460 --- /dev/null +++ b/build.bat @@ -0,0 +1,72 @@ +@echo off +setlocal enabledelayedexpansion + +echo === 1. Cleaning Workspace === +if exist bin rmdir /s /q bin +if exist stage rmdir /s /q stage +if exist dist rmdir /s /q dist +mkdir bin\classes +mkdir bin\test-classes +mkdir stage +mkdir dist + +echo === 2. Compiling Production Code === +dir /s /b src\main\java\*.java > sources.txt +javac -d bin\classes -cp "lib/*" @sources.txt +if %errorlevel% neq 0 exit /b %errorlevel% + +echo === 3. Compiling Test Code === +dir /s /b src\test\java\*.java > test-sources.txt +javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt +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) + +rem JUnit's --class-path does NOT expand lib\* -> build it explicitly +set "TEST_CP=bin\classes;bin\test-classes" +for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j" + +java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath +if %errorlevel% neq 0 ( + echo [X] Tests failed! Aborting build package. + exit /b %errorlevel% +) +echo [OK] Tests passed successfully! + +echo === 5. Extracting Dependencies for Fat JAR === +cd stage +for %%j in (..\lib\*.jar) do ( + echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul + if errorlevel 1 ( + echo Extracting: %%~nxj + jar -xf "%%j" + ) +) + +rem Strip signatures + manifests (they break repacking) but KEEP +rem META-INF\services so ServiceLoader-based deps still work at runtime. +if exist META-INF ( + del /s /q META-INF\*.SF >nul 2>&1 + del /s /q META-INF\*.RSA >nul 2>&1 + del /s /q META-INF\*.DSA >nul 2>&1 + del /q META-INF\MANIFEST.MF >nul 2>&1 +) +cd .. + +echo === 6. Merging Assets into Fat JAR === +rem Merge ONLY production classes on top of the extracted deps +xcopy /e /q /y /i bin\classes\* stage\ >nul +rem Package the whole tree (deps + your classes), not just stage\classes +jar cfe dist/app.jar com.example.App -C stage . +if %errorlevel% neq 0 exit /b %errorlevel% + +del sources.txt test-sources.txt >nul 2>&1 +rmdir /s /q stage +echo ====================================== +echo Fat JAR Created! Run it with: +echo java -jar dist/app.jar +echo ====================================== +pause diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6fdf7e1 --- /dev/null +++ b/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e + +echo "=== 1. Cleaning Workspace ===" +rm -rf bin stage +mkdir -p bin/classes bin/test-classes stage dist # dist was never created + +echo "=== 2. Compiling Production Code ===" +javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java') + +echo "=== 3. Compiling Test Code ===" +# prod classes are in bin/classes, not bin +javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java') + +echo "=== 4. Running Automated Tests ===" +JUNIT_JAR=$(find lib -maxdepth 1 -name '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/classes:bin/test-classes: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 + [ -f "$jarfile" ] || continue + case "$(basename "$jarfile")" in + junit-platform-console-standalone-*) continue ;; + esac + echo "Extracting: $(basename "$jarfile")" + jar -xf "$jarfile" +done + +# Strip signatures + manifests (they break repacking), but KEEP +# META-INF/services so ServiceLoader-based deps still work at runtime. +find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true +cd .. + +echo "=== 6. Merging Assets into Fat JAR ===" +# Merge YOUR production classes on top of the extracted deps +cp -r bin/classes/. stage/ +# Package the whole tree (deps + your classes), not just stage/classes +jar cfe dist/app.jar com.example.App -C stage . + +rm -rf stage +echo "======================================" +echo "🎉 Fat JAR Created! Run it with:" +echo "java -jar dist/app.jar" +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 Binary files /dev/null and b/lib/junit-platform-console-standalone-6.1.1.jar differ diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..8480652 --- /dev/null +++ b/run.bat @@ -0,0 +1,16 @@ +@echo off +:: clean old binaries +rmdir /s /q bin +mkdir bin + +:: compile source files and include libraries +javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java + +:: run the application if compilation succeeded +if %errorlevel% equ 0 ( + echo --- Running Application --- + java -cp "bin/classes;lib/*" com.example.App +) else ( + echo Compilation failed. +) +pause diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..55f1094 --- /dev/null +++ b/run.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# clean up +rm -rf bin && mkdir bin + +# run the app if compilation succeeded +if javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java; then + echo "--- Running Application ---" + java -cp "bin/classes:lib/*" com.example.App +else + echo "Compilation failed." +fi diff --git a/src/confing.properties b/src/confing.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/example/App.java b/src/main/java/com/example/App.java new file mode 100644 index 0000000..5777405 --- /dev/null +++ b/src/main/java/com/example/App.java @@ -0,0 +1,7 @@ +package com.example; + +public class App { + public static void main() { + IO.println("Hello World"); + } +} diff --git a/src/test/java/com/example/AppTest.java b/src/test/java/com/example/AppTest.java new file mode 100644 index 0000000..0b08c28 --- /dev/null +++ b/src/test/java/com/example/AppTest.java @@ -0,0 +1,3 @@ +package com.example; + +public class AppTest {} -- cgit v1.2.3