diff options
| -rw-r--r-- | .classpath | 20 | ||||
| -rw-r--r-- | .gitignore | 12 | ||||
| -rw-r--r-- | .project | 28 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | build.bat | 72 | ||||
| -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 | 16 | ||||
| -rw-r--r-- | run.sh | 12 | ||||
| -rw-r--r-- | src/confing.properties | 0 | ||||
| -rw-r--r-- | src/main/java/com/example/App.java | 7 | ||||
| -rw-r--r-- | src/test/java/com/example/AppTest.java | 3 |
12 files changed, 232 insertions, 0 deletions
diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..7f8bc25 --- /dev/null +++ b/.classpath | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <classpath> | ||
| 3 | <!-- Defines your source folder --> | ||
| 4 | <classpathentry kind="src" output="bin/classes" path="src/main/java"> | ||
| 5 | <attributes> | ||
| 6 | <attribute name="optional" value="true"/> | ||
| 7 | </attributes> | ||
| 8 | </classpathentry> | ||
| 9 | <classpathentry kind="src" output="bin/test-classes" path="src/test/java"> | ||
| 10 | <attributes> | ||
| 11 | <attribute name="optional" value="true"/> | ||
| 12 | <attribute name="test" value="true"/> | ||
| 13 | </attributes> | ||
| 14 | </classpathentry> | ||
| 15 | <!-- Defines the standard Java System Library --> | ||
| 16 | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
| 17 | <!-- Defines where compiled .class files go --> | ||
| 18 | <classpathentry kind="output" path="bin"/> | ||
| 19 | </classpath> | ||
| 20 | |||
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..774d6b1 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | # Ignore compiled Java bytecode | ||
| 2 | bin/ | ||
| 3 | stage/ | ||
| 4 | dist/ | ||
| 5 | *.class | ||
| 6 | |||
| 7 | # Ignore OS-specific files | ||
| 8 | .DS_Store | ||
| 9 | Thumbs.db | ||
| 10 | |||
| 11 | config.properties | ||
| 12 | |||
diff --git a/.project b/.project new file mode 100644 index 0000000..c3b90e2 --- /dev/null +++ b/.project | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <projectDescription> | ||
| 3 | <name>App</name> | ||
| 4 | <comment></comment> | ||
| 5 | <projects> | ||
| 6 | </projects> | ||
| 7 | <buildSpec> | ||
| 8 | <buildCommand> | ||
| 9 | <name>org.eclipse.jdt.core.javabuilder</name> | ||
| 10 | <arguments> | ||
| 11 | </arguments> | ||
| 12 | </buildCommand> | ||
| 13 | </buildSpec> | ||
| 14 | <natures> | ||
| 15 | <nature>org.eclipse.jdt.core.javanature</nature> | ||
| 16 | </natures> | ||
| 17 | <filteredResources> | ||
| 18 | <filter> | ||
| 19 | <id>1784965956299</id> | ||
| 20 | <name></name> | ||
| 21 | <type>30</type> | ||
| 22 | <matcher> | ||
| 23 | <id>org.eclipse.core.resources.regexFilterMatcher</id> | ||
| 24 | <arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> | ||
| 25 | </matcher> | ||
| 26 | </filter> | ||
| 27 | </filteredResources> | ||
| 28 | </projectDescription> | ||
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 @@ | |||
| 1 | @echo off | ||
| 2 | setlocal enabledelayedexpansion | ||
| 3 | |||
| 4 | echo === 1. Cleaning Workspace === | ||
| 5 | if exist bin rmdir /s /q bin | ||
| 6 | if exist stage rmdir /s /q stage | ||
| 7 | if exist dist rmdir /s /q dist | ||
| 8 | mkdir bin\classes | ||
| 9 | mkdir bin\test-classes | ||
| 10 | mkdir stage | ||
| 11 | mkdir dist | ||
| 12 | |||
| 13 | echo === 2. Compiling Production Code === | ||
| 14 | dir /s /b src\main\java\*.java > sources.txt | ||
| 15 | javac -d bin\classes -cp "lib/*" @sources.txt | ||
| 16 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 17 | |||
| 18 | echo === 3. Compiling Test Code === | ||
| 19 | dir /s /b src\test\java\*.java > test-sources.txt | ||
| 20 | javac -d bin\test-classes -cp "bin\classes;lib/*" @test-sources.txt | ||
| 21 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 22 | |||
| 23 | echo === 4. Running Automated Tests === | ||
| 24 | set "JUNIT_JAR=" | ||
| 25 | for %%f in (lib\junit-platform-console-standalone-*.jar) do set "JUNIT_JAR=%%f" | ||
| 26 | if not defined JUNIT_JAR (echo JUnit jar missing. & exit /b 1) | ||
| 27 | |||
| 28 | rem JUnit's --class-path does NOT expand lib\* -> build it explicitly | ||
| 29 | set "TEST_CP=bin\classes;bin\test-classes" | ||
| 30 | for %%j in (lib\*.jar) do set "TEST_CP=!TEST_CP!;%%j" | ||
| 31 | |||
| 32 | java -jar "!JUNIT_JAR!" execute -cp "!TEST_CP!" --scan-classpath | ||
| 33 | if %errorlevel% neq 0 ( | ||
| 34 | echo [X] Tests failed! Aborting build package. | ||
| 35 | exit /b %errorlevel% | ||
| 36 | ) | ||
| 37 | echo [OK] Tests passed successfully! | ||
| 38 | |||
| 39 | echo === 5. Extracting Dependencies for Fat JAR === | ||
| 40 | cd stage | ||
| 41 | for %%j in (..\lib\*.jar) do ( | ||
| 42 | echo %%~nxj | findstr /i "junit-platform-console-standalone" >nul | ||
| 43 | if errorlevel 1 ( | ||
| 44 | echo Extracting: %%~nxj | ||
| 45 | jar -xf "%%j" | ||
| 46 | ) | ||
| 47 | ) | ||
| 48 | |||
| 49 | rem Strip signatures + manifests (they break repacking) but KEEP | ||
| 50 | rem META-INF\services so ServiceLoader-based deps still work at runtime. | ||
| 51 | if exist META-INF ( | ||
| 52 | del /s /q META-INF\*.SF >nul 2>&1 | ||
| 53 | del /s /q META-INF\*.RSA >nul 2>&1 | ||
| 54 | del /s /q META-INF\*.DSA >nul 2>&1 | ||
| 55 | del /q META-INF\MANIFEST.MF >nul 2>&1 | ||
| 56 | ) | ||
| 57 | cd .. | ||
| 58 | |||
| 59 | echo === 6. Merging Assets into Fat JAR === | ||
| 60 | rem Merge ONLY production classes on top of the extracted deps | ||
| 61 | xcopy /e /q /y /i bin\classes\* stage\ >nul | ||
| 62 | rem Package the whole tree (deps + your classes), not just stage\classes | ||
| 63 | jar cfe dist/app.jar com.example.App -C stage . | ||
| 64 | if %errorlevel% neq 0 exit /b %errorlevel% | ||
| 65 | |||
| 66 | del sources.txt test-sources.txt >nul 2>&1 | ||
| 67 | rmdir /s /q stage | ||
| 68 | echo ====================================== | ||
| 69 | echo Fat JAR Created! Run it with: | ||
| 70 | echo java -jar dist/app.jar | ||
| 71 | echo ====================================== | ||
| 72 | 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 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | set -e | ||
| 3 | |||
| 4 | echo "=== 1. Cleaning Workspace ===" | ||
| 5 | rm -rf bin stage | ||
| 6 | mkdir -p bin/classes bin/test-classes stage dist # dist was never created | ||
| 7 | |||
| 8 | echo "=== 2. Compiling Production Code ===" | ||
| 9 | javac -d bin/classes -cp "lib/*" @<(find src/main/java -name '*.java') | ||
| 10 | |||
| 11 | echo "=== 3. Compiling Test Code ===" | ||
| 12 | # prod classes are in bin/classes, not bin | ||
| 13 | javac -d bin/test-classes -cp "bin/classes:lib/*" @<(find src/test/java -name '*.java') | ||
| 14 | |||
| 15 | echo "=== 4. Running Automated Tests ===" | ||
| 16 | JUNIT_JAR=$(find lib -maxdepth 1 -name 'junit-platform-console-standalone-*.jar' | head -n 1) | ||
| 17 | if [ -z "$JUNIT_JAR" ]; then | ||
| 18 | echo "JUnit jar missing." | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | |||
| 22 | set +e | ||
| 23 | java -jar "$JUNIT_JAR" execute \ | ||
| 24 | -cp "bin/classes:bin/test-classes:lib/*" \ | ||
| 25 | --scan-classpath | ||
| 26 | TEST_STATUS=$? | ||
| 27 | set -e | ||
| 28 | |||
| 29 | if [ $TEST_STATUS -ne 0 ]; then | ||
| 30 | echo "❌ Tests failed! Aborting build package." | ||
| 31 | exit 1 | ||
| 32 | fi | ||
| 33 | echo "✅ Tests passed successfully!" | ||
| 34 | |||
| 35 | echo "=== 5. Extracting Dependencies for Fat JAR ===" | ||
| 36 | cd stage | ||
| 37 | for jarfile in ../lib/*.jar; do | ||
| 38 | [ -f "$jarfile" ] || continue | ||
| 39 | case "$(basename "$jarfile")" in | ||
| 40 | junit-platform-console-standalone-*) continue ;; | ||
| 41 | esac | ||
| 42 | echo "Extracting: $(basename "$jarfile")" | ||
| 43 | jar -xf "$jarfile" | ||
| 44 | done | ||
| 45 | |||
| 46 | # Strip signatures + manifests (they break repacking), but KEEP | ||
| 47 | # META-INF/services so ServiceLoader-based deps still work at runtime. | ||
| 48 | find META-INF -type f \( -name '*.SF' -o -name '*.RSA' -o -name '*.DSA' -o -name 'MANIFEST.MF' \) -delete 2>/dev/null || true | ||
| 49 | cd .. | ||
| 50 | |||
| 51 | echo "=== 6. Merging Assets into Fat JAR ===" | ||
| 52 | # Merge YOUR production classes on top of the extracted deps | ||
| 53 | cp -r bin/classes/. stage/ | ||
| 54 | # Package the whole tree (deps + your classes), not just stage/classes | ||
| 55 | jar cfe dist/app.jar com.example.App -C stage . | ||
| 56 | |||
| 57 | rm -rf stage | ||
| 58 | echo "======================================" | ||
| 59 | echo "🎉 Fat JAR Created! Run it with:" | ||
| 60 | echo "java -jar dist/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 | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | @echo off | ||
| 2 | :: clean old binaries | ||
| 3 | rmdir /s /q bin | ||
| 4 | mkdir bin | ||
| 5 | |||
| 6 | :: compile source files and include libraries | ||
| 7 | javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java | ||
| 8 | |||
| 9 | :: run the application if compilation succeeded | ||
| 10 | if %errorlevel% equ 0 ( | ||
| 11 | echo --- Running Application --- | ||
| 12 | java -cp "bin/classes;lib/*" com.example.App | ||
| 13 | ) else ( | ||
| 14 | echo Compilation failed. | ||
| 15 | ) | ||
| 16 | pause | ||
| @@ -0,0 +1,12 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # clean up | ||
| 4 | rm -rf bin && mkdir bin | ||
| 5 | |||
| 6 | # run the app if compilation succeeded | ||
| 7 | if javac -d "bin/classes" -cp "lib/*" src/main/java/com/example/App.java; then | ||
| 8 | echo "--- Running Application ---" | ||
| 9 | java -cp "bin/classes:lib/*" com.example.App | ||
| 10 | else | ||
| 11 | echo "Compilation failed." | ||
| 12 | fi | ||
diff --git a/src/confing.properties b/src/confing.properties new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/confing.properties | |||
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 @@ | |||
| 1 | package com.example; | ||
| 2 | |||
| 3 | public class App { | ||
| 4 | public static void main() { | ||
| 5 | IO.println("Hello World"); | ||
| 6 | } | ||
| 7 | } | ||
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 @@ | |||
| 1 | package com.example; | ||
| 2 | |||
| 3 | public class AppTest {} | ||