修改运行脚本

This commit is contained in:
张家训
2026-06-19 17:25:47 +08:00
parent 400a2bffc2
commit 0939c61c1d
4 changed files with 159 additions and 67 deletions
Binary file not shown.
+20 -7
View File
@@ -17,7 +17,8 @@
<java.version>17</java.version> <java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release> <!-- 当 JDK 版本与项目不匹配时,取消注释下行 -->
<!-- <maven.compiler.release>17</maven.compiler.release> -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Maven 编译/测试启动时的 JVM 参数,确保 IDEA 内运行不乱码 --> <!-- Maven 编译/测试启动时的 JVM 参数,确保 IDEA 内运行不乱码 -->
@@ -26,13 +27,10 @@
<javafx.version>17.0.14</javafx.version> <javafx.version>17.0.14</javafx.version>
<!-- AtlantaFX 版本 --> <!-- AtlantaFX 版本 -->
<atlantafx.version>2.0.1</atlantafx.version> <atlantafx.version>2.0.1</atlantafx.version>
<!-- 指定 JDK 17 路径(系统默认 JDK 8 时启用) -->
<jdk17.home>C:\Program Files\Java\jdk-17</jdk17.home>
</properties> </properties>
<repositories> <repositories>
<!-- 本地文件仓库:存放外部 jar,随项目分发 -->
<repository>
<id>local-lib-repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
<!-- AtlantaFX Maven 仓库 --> <!-- AtlantaFX Maven 仓库 -->
<repository> <repository>
<id>sonatype-snapshots</id> <id>sonatype-snapshots</id>
@@ -196,6 +194,20 @@
<build> <build>
<plugins> <plugins>
<!-- 强制使用 JDK 17 编译(系统默认 JDK 8 时必需) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>17</release>
<verbose>true</verbose>
<fork>true</fork>
<executable>${jdk17.home}\bin\javac</executable>
<compilerVersion>17</compilerVersion>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
@@ -228,7 +240,8 @@
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass> <mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
</classPath> </classPath>
<jre> <jre>
<minVersion>1.8.0</minVersion> <path>jre</path>
<minVersion>17</minVersion>
<opts> <opts>
<opt>-Dfile.encoding=UTF-8</opt> <opt>-Dfile.encoding=UTF-8</opt>
</opts> </opts>
+137 -31
View File
@@ -1,31 +1,37 @@
@echo off @echo off
chcp 65001 >nul chcp 65001 >nul
setlocal enabledelayedexpansion setlocal
:: ============================================ :: ============================================
:: WorkUtils 生产打包脚本 :: WorkUtils 生产打包脚本(免安装版)
:: 输出:target\dist\workutils-v{version}.zip(含 exe + jar + bat + config) :: 输出:target\dist\workutils-v{version}.zip
:: (含 exe + 内嵌JRE + jar + 启动脚本)
:: ============================================ :: ============================================
::: 切换到项目根目录 ::: 切换到项目根目录
cd /d "%~dp0.." cd /d "%~dp0.."
set PROJECT_DIR=%CD% set "PROJECT_DIR=%CD%"
set TARGET=%PROJECT_DIR%\target set "TARGET=%PROJECT_DIR%\target"
set DIST=%TARGET%\dist set "DIST=%TARGET%\dist"
set VERSION= set "VERSION="
echo. echo.
echo ========== WorkUtils 生产构建 ========== echo ========== WorkUtils 生产构建 ==========
echo 项目目录: %PROJECT_DIR%
echo. echo.
:: 1. 杀掉可能占用 target 的进程 ::: ============================================================
echo [1/4] Clean stale processes... ::: 步骤 1:清理残留进程
::: ============================================================
echo [1/5] Clean stale processes...
taskkill /f /im java.exe 2>nul taskkill /f /im java.exe 2>nul
taskkill /f /im workutils.exe 2>nul taskkill /f /im workutils.exe 2>nul
:: 2. Maven 打包 ::: ============================================================
::: 步骤 2:Maven 打包
::: ============================================================
echo. echo.
echo [2/4] Maven build... echo [2/5] Maven build...
call "%PROJECT_DIR%\mvnw.cmd" clean package -DskipTests -q call "%PROJECT_DIR%\mvnw.cmd" clean package -DskipTests -q
if %errorlevel% neq 0 ( if %errorlevel% neq 0 (
echo [ERROR] Maven build failed! echo [ERROR] Maven build failed!
@@ -33,42 +39,142 @@ if %errorlevel% neq 0 (
exit /b 1 exit /b 1
) )
:: 3. 提取版本号 ::: ============================================================
for /f "tokens=2 delims=>" %%i in ('findstr /c:"<version>" "%PROJECT_DIR%\pom.xml" ^| findstr /v "xml" ^| findstr /n "1" ^| findstr "1:"') do ( ::: 步骤 3:提取版本号(PowerShell 解析 pom.xml)
for /f "tokens=1 delims=<" %%v in ("%%i") do set VERSION=%%v ::: ============================================================
)
if "%VERSION%"=="" set VERSION=0.0.1-SNAPSHOT
:: 4. 准备发布目录
echo. echo.
echo [3/4] Assemble distribution... echo [3/5] Read version from pom.xml...
for /f "usebackq delims=" %%a in (`powershell -NoProfile -NonInteractive -Command "([xml](Get-Content -Encoding UTF8 '%PROJECT_DIR%\pom.xml')).project.version"`) do set "VERSION=%%a"
if "%VERSION%"=="" set "VERSION=0.0.1-SNAPSHOT"
echo 版本: %VERSION%
::: ============================================================
::: 步骤 4:生成精简 JRE(jlink 内嵌 Java 17 + JavaFX)
::: ============================================================
echo.
echo [4/5] Generate bundled JRE...
::: 4.1 查找 JDK 17(环境变量 JDK17_HOME > 默认路径)
if not defined JDK17_HOME (
for %%d in (
"C:\Program Files\Java\jdk-17"
"C:\Program Files\Eclipse Adoptium\jdk-17.0.0.35-hotspot"
"C:\Program Files\Java\jdk-17.0.14"
"%JAVA_HOME%"
) do (
if exist "%%~d\bin\jlink.exe" (
set "JDK17_HOME=%%~d"
goto :jdk17_found
)
)
echo [ERROR] Cannot find JDK 17 with jlink.exe
echo Please set JDK17_HOME environment variable
pause & exit /b 1
)
:jdk17_found
::: 4.2 查找 JavaFX SDK(环境变量 JFX_SDK_HOME > 默认路径)
if not defined JFX_SDK_HOME (
for %%d in (
"C:\Program Files\Java\javafx-sdk-17.0.15"
"C:\Program Files\Java\javafx-sdk-17.0.14"
"C:\Program Files\Java\javafx-sdk-17"
) do (
if exist "%%~d\lib\javafx.base.jar" (
set "JFX_SDK_HOME=%%~d"
goto :jfx_found
)
)
echo [ERROR] Cannot find JavaFX SDK
echo Please set JFX_SDK_HOME environment variable
pause & exit /b 1
)
:jfx_found
echo JDK : %JDK17_HOME%
echo JavaFX: %JFX_SDK_HOME%
::: 4.3 清理旧 JRE
if exist "%TARGET%\jre" rd /s /q "%TARGET%\jre"
::: 4.4 执行 jlink
echo Running jlink, please wait...
"%JDK17_HOME%\bin\jlink.exe" ^
--module-path "%JFX_SDK_HOME%\lib;%JDK17_HOME%\jmods" ^
--add-modules java.base,java.desktop,java.logging,java.management,java.naming,java.sql,java.xml,java.xml.crypto,java.instrument,java.security.jgss,java.security.sasl,jdk.unsupported,jdk.management,java.scripting,jdk.crypto.ec,java.net.http,javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.web,javafx.swing ^
--output "%TARGET%\jre" ^
--strip-debug --no-header-files --no-man-pages --compress=2
if %errorlevel% neq 0 (
echo [ERROR] jlink failed!
pause
exit /b 1
)
echo [OK] JRE generated : %TARGET%\jre
::: ============================================================
::: 步骤 5:组装发布目录 & 打包 ZIP
::: ============================================================
echo.
echo [5/5] Assemble distribution...
::: 清理旧发布目录
if exist "%DIST%" rd /s /q "%DIST%" if exist "%DIST%" rd /s /q "%DIST%"
mkdir "%DIST%\workutils" 2>nul mkdir "%DIST%\workutils" 2>nul
::: 复制 EXE
if exist "%TARGET%\workutils.exe" (
copy /y "%TARGET%\workutils.exe" "%DIST%\workutils\" >nul copy /y "%TARGET%\workutils.exe" "%DIST%\workutils\" >nul
copy /y "%TARGET%\workutils-%VERSION%.jar" "%DIST%\workutils\" >nul echo [OK] workutils.exe
) else (
echo [WARN] workutils.exe not found!
)
:: 生成发布用的启动脚本(JAR 在同一个目录下) ::: 复制 JAR
>"%DIST%\workutils\start.bat" ( for %%j in ("%TARGET%\workutils-*.jar") do (
copy /y "%%j" "%DIST%\workutils\" >nul
echo [OK] %%~nxj
)
::: 复制内嵌 JRE
if exist "%TARGET%\jre\bin\java.exe" (
xcopy /e /i /q "%TARGET%\jre" "%DIST%\workutils\jre\" >nul
echo [OK] jre/ ^(bundled Java 17 + JavaFX^)
) else (
echo [WARN] jre not found in target!
)
::: ============================================================
::: 生成 start.bat(备选启动方式)
::: ============================================================
(
echo @echo off echo @echo off
echo chcp 65001 ^>nul echo chcp 65001 ^>nul
echo title WorkUtils echo title WorkUtils
echo java -jar "%%~dp0workutils-%VERSION%.jar" %%* echo java -jar "%%~dp0workutils-%VERSION%.jar" %%*
echo pause echo pause
) ) > "%DIST%\workutils\start.bat"
echo [OK] start.bat
:: 打包成 zip(保留 workutils 目录结构) ::: ============================================================
set ZIPNAME=workutils-v%VERSION% ::: 打包 ZIP
powershell -Command "Compress-Archive -Path '%DIST%\workutils' -DestinationPath '%DIST%\%ZIPNAME%.zip' -Force" ::: ============================================================
set "ZIPNAME=workutils-v%VERSION%"
echo 正在压缩 %ZIPNAME%.zip ...
powershell -Command ^
"Compress-Archive -Path '%DIST%\workutils' -DestinationPath '%DIST%\%ZIPNAME%.zip' -Force"
echo [OK] %ZIPNAME%.zip
:: 5. 完成 ::: ============================================================
::: 完成
::: ============================================================
echo. echo.
echo [4/4] Build complete! echo ============================================
echo Build Complete ^! v%VERSION%
echo ============================================ echo ============================================
echo Output: echo Output:
echo exe : target\workutils.exe echo %DIST%\workutils\
echo jar : target\workutils-%VERSION%.jar echo %DIST%\%ZIPNAME%.zip
echo zip : target\dist\%ZIPNAME%.zip
echo ============================================ echo ============================================
echo. echo.
pause pause
-27
View File
@@ -1,27 +0,0 @@
import java.nio.file.*;
import java.util.*;
public class fix_urls {
public static void main(String[] args) throws Exception {
// Fix both template and data files
String[] files = {"data/project_paths.txt", "src/main/resources/templates/project_paths.txt"};
for (String file : files) {
Path p = Paths.get(file);
List<String> lines = Files.readAllLines(p, java.nio.charset.StandardCharsets.UTF_8);
int fixed = 0;
for (int i = 0; i < lines.size(); i++) {
String l = lines.get(i);
if (l.contains("=") && l.endsWith("cf/")) {
int eq = l.lastIndexOf('=');
String path = l.substring(0, eq).trim();
String url = l.substring(eq + 1).trim();
String proj = path.substring(path.lastIndexOf('/') + 1);
lines.set(i, path + "=" + url + proj + ".git");
fixed++;
}
}
Files.write(p, lines, java.nio.charset.StandardCharsets.UTF_8);
System.out.println(file + ": fixed " + fixed + " lines, total " + lines.size());
}
}
}