Files
workutils/scripts/start.bat
T
2026-06-23 20:25:40 +08:00

57 lines
2.1 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
title WorkUtils
:: 切到脚本所在目录的父目录(即项目根目录)
:: 当脚本在 scripts/ 时 → 项目根;在 target/ 时 → 项目根
cd /d "%~dp0.."
:: 从 pom.xml 读取版本号
set "VERSION="
for /f "usebackq delims=" %%a in (`powershell -NoProfile -NonInteractive -Command "([xml](Get-Content -Encoding UTF8 '%CD%\pom.xml')).project.version"`) do set "VERSION=%%a"
if "%VERSION%"=="" set "VERSION=0.0.1-SNAPSHOT"
:: 优先匹配版本号精确的 JAR,找不到回退通配符
set "JAR="
if exist "target\workutils-%VERSION%.jar" set "JAR=target\workutils-%VERSION%.jar"
if "%JAR%"=="" for %%j in ("target\workutils-*.jar") do set "JAR=%%j"
if "%JAR%"=="" (
echo [ERROR] JAR not found in target\ Run build_release.bat first.
pause & exit /b 1
)
:: ======== 查找可用的 Java 17+ ========
set "JAVA_EXE="
:: 1) 优先用 jlink 生成的内嵌 JRE(运行过 build_release.bat 后产生)
if exist "target\jre\bin\java.exe" set "JAVA_EXE=target\jre\bin\java.exe"
:: 2) 检查 JDK17_HOME 环境变量
if "%JAVA_EXE%"=="" if defined JDK17_HOME if exist "%JDK17_HOME%\bin\java.exe" set "JAVA_EXE=%JDK17_HOME%\bin\java.exe"
:: 3) 检查 JAVA_HOME(可能是 JDK 17)
if "%JAVA_EXE%"=="" if defined JAVA_HOME if exist "%JAVA_HOME%\bin\java.exe" set "JAVA_EXE=%JAVA_HOME%\bin\java.exe"
:: 4) 回退到 PATH 上的 java
if "%JAVA_EXE%"=="" set "JAVA_EXE=java"
:: 检查 Java 版本是否 ≥ 17
for /f "tokens=3" %%v in ('"%JAVA_EXE%" -version 2^>^&1 ^| findstr /i "version"') do set "JAVA_VER=%%~v"
for /f "tokens=1 delims=." %%m in ("%JAVA_VER%") do set "MAJOR=%%m"
if "%MAJOR%"=="1" for /f "tokens=2 delims=." %%m in ("%JAVA_VER%") do set "MAJOR=%%m"
if %MAJOR% LSS 17 (
echo [ERROR] Java %JAVA_VER% found. WorkUtils requires Java 17+.
echo Path: %JAVA_EXE%
echo Download JDK 17+ from https://adoptium.net/
pause & exit /b 1
)
echo ====================================
echo WorkUtils v%VERSION%
echo Java: %JAVA_VER% ^( %JAVA_EXE% ^)
echo ====================================
echo.
"%JAVA_EXE%" -Dfile.encoding=UTF-8 -jar "%JAR%" %*
if %errorlevel% neq 0 pause