|
| 1 | +@rem *************************************************************************** |
| 2 | +@rem Copyright (c) 2025 James M. Zhou |
| 3 | +@rem |
| 4 | +@rem Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +@rem you may not use this file except in compliance with the License. |
| 6 | +@rem You may obtain a copy of the License at |
| 7 | +@rem |
| 8 | +@rem http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +@rem |
| 10 | +@rem Unless required by applicable law or agreed to in writing, software |
| 11 | +@rem distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +@rem See the License for the specific language governing permissions and |
| 14 | +@rem limitations under the License. |
| 15 | +@rem *************************************************************************** |
| 16 | +@echo off |
| 17 | + |
| 18 | +@REM Set the local Maven repository path for tinystruct.jar |
| 19 | +set "MAVEN_REPO=%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct" |
| 20 | +@REM Consolidate classpath entries, initialize ROOT and VERSION |
| 21 | +set "ROOT=%~dp0.." |
| 22 | +set "VERSION=1.6.6" |
| 23 | + |
| 24 | +@REM Define the paths for tinystruct jars in the Maven repository |
| 25 | +set "DEFAULT_JAR_FILE=%MAVEN_REPO%\%VERSION%\tinystruct-%VERSION%.jar" |
| 26 | +set "DEFAULT_JAR_FILE_WITH_DEPENDENCIES=%MAVEN_REPO%\%VERSION%\tinystruct-%VERSION%-jar-with-dependencies.jar" |
| 27 | + |
| 28 | +REM Check which jar to use for extracting Maven Wrapper |
| 29 | +if exist "%DEFAULT_JAR_FILE_WITH_DEPENDENCIES%" ( |
| 30 | + set "JAR_PATH=%DEFAULT_JAR_FILE_WITH_DEPENDENCIES%" |
| 31 | +) else ( |
| 32 | + set "JAR_PATH=%DEFAULT_JAR_FILE%" |
| 33 | +) |
| 34 | + |
| 35 | +@REM Check if JAVA_HOME is set and valid |
| 36 | +if "%JAVA_HOME%" == "" ( |
| 37 | + echo Error: JAVA_HOME not found in your environment. >&2 |
| 38 | + echo Please set the JAVA_HOME variable in your environment to match the location of your Java installation. >&2 |
| 39 | + exit /B 1 |
| 40 | +) |
| 41 | + |
| 42 | +if not exist "%JAVA_HOME%\bin\java.exe" ( |
| 43 | + echo Error: JAVA_HOME is set to an invalid directory. >&2 |
| 44 | + echo JAVA_HOME = "%JAVA_HOME%" >&2 |
| 45 | + echo Please set the JAVA_HOME variable in your environment to match the location of your Java installation. >&2 |
| 46 | + exit /B 1 |
| 47 | +) |
| 48 | + |
| 49 | +set "JAVA_CMD=%JAVA_HOME%\bin\java.exe" |
| 50 | + |
| 51 | +@REM Check if the Maven Wrapper is already available |
| 52 | +if not exist "mvnw" ( |
| 53 | + echo Maven Wrapper not found. Extracting from JAR... |
| 54 | + |
| 55 | + @REM Run Java code to extract the ZIP file from the JAR |
| 56 | + %JAVA_CMD% -cp "%JAR_PATH%" org.tinystruct.system.Dispatcher maven-wrapper --jar-file-path "%JAR_PATH%" --destination-dir "%ROOT%" |
| 57 | + |
| 58 | + if exist "%ROOT%\maven-wrapper.zip" ( |
| 59 | + @REM Now unzip the Maven Wrapper files |
| 60 | + powershell -Command "Expand-Archive -Path '%ROOT%\maven-wrapper.zip' -DestinationPath '%ROOT%'" |
| 61 | + @REM Delete the ZIP file after extraction |
| 62 | + del /F /Q "%ROOT%\maven-wrapper.zip" |
| 63 | + echo Maven wrapper setup completed. |
| 64 | + ) else ( |
| 65 | + echo Error: Maven wrapper ZIP file not found in JAR. |
| 66 | + exit /B 1 |
| 67 | + ) |
| 68 | +) |
| 69 | + |
| 70 | +set "classpath=%ROOT%\target\classes;%ROOT%\lib\tinystruct-%VERSION%-jar-with-dependencies.jar;%ROOT%\lib\tinystruct-%VERSION%.jar;%ROOT%\lib\*;%ROOT%\WEB-INF\lib\*;%ROOT%\WEB-INF\classes;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%-jar-with-dependencies.jar;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%.jar" |
| 71 | + |
| 72 | +@REM Run Java application |
| 73 | +%JAVA_CMD% -cp "%classpath%" org.tinystruct.system.Dispatcher %* |
0 commit comments