支持打包
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: ============================================
|
||||
:: WorkUtils 生产打包脚本
|
||||
:: 输出:target\dist\workutils-v{version}.zip(含 exe + jar + bat + config)
|
||||
:: ============================================
|
||||
|
||||
set PROJECT_DIR=%~dp0
|
||||
set TARGET=%PROJECT_DIR%target
|
||||
set DIST=%TARGET%\dist
|
||||
set VERSION=
|
||||
|
||||
echo.
|
||||
echo ========== WorkUtils 生产构建 ==========
|
||||
echo.
|
||||
|
||||
:: 1. 杀掉可能占用 target 的进程
|
||||
echo [1/4] 清理残留进程...
|
||||
taskkill /f /im java.exe 2>nul
|
||||
taskkill /f /im workutils.exe 2>nul
|
||||
|
||||
:: 2. Maven 打包
|
||||
echo.
|
||||
echo [2/4] Maven 编译打包...
|
||||
call "%PROJECT_DIR%mvnw.cmd" clean package -DskipTests -q
|
||||
if %errorlevel% neq 0 (
|
||||
echo [ERROR] Maven 打包失败!
|
||||
pause
|
||||
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 (
|
||||
for /f "tokens=1 delims=<" %%v in ("%%i") do set VERSION=%%v
|
||||
)
|
||||
if "%VERSION%"=="" set VERSION=0.0.1-SNAPSHOT
|
||||
|
||||
:: 4. 准备发布目录
|
||||
echo.
|
||||
echo [3/4] 组装发布包...
|
||||
if exist "%DIST%" rd /s /q "%DIST%"
|
||||
mkdir "%DIST%\workutils" 2>nul
|
||||
|
||||
copy /y "%TARGET%\workutils.exe" "%DIST%\workutils\" >nul
|
||||
copy /y "%TARGET%\workutils-%VERSION%.jar" "%DIST%\workutils\" >nul
|
||||
|
||||
:: 生成发布用的启动脚本(JAR 在同一个目录下)
|
||||
>"%DIST%\workutils\start.bat" (
|
||||
echo @echo off
|
||||
echo chcp 65001 ^>nul
|
||||
echo title WorkUtils
|
||||
echo java -jar "%%~dp0workutils-%VERSION%.jar" %%*
|
||||
echo pause
|
||||
)
|
||||
|
||||
:: 打包成 zip(保留 workutils 目录结构)
|
||||
set ZIPNAME=workutils-v%VERSION%
|
||||
powershell -Command "Compress-Archive -Path '%DIST%\workutils' -DestinationPath '%DIST%\%ZIPNAME%.zip' -Force"
|
||||
|
||||
:: 5. 完成
|
||||
echo.
|
||||
echo [4/4] 构建完成!
|
||||
echo ============================================
|
||||
echo 产物位置:
|
||||
echo exe : target\workutils.exe
|
||||
echo jar : target\workutils-%VERSION%.jar
|
||||
echo zip : target\dist\%ZIPNAME%.zip
|
||||
echo ============================================
|
||||
echo.
|
||||
pause
|
||||
@@ -187,6 +187,18 @@
|
||||
<systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<!-- JNA: 用于 Windows 控制台代码页切换 (UTF-8) -->
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>5.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna-platform</artifactId>
|
||||
<version>5.14.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -196,6 +208,34 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.akathist.maven.plugins.launch4j</groupId>
|
||||
<artifactId>launch4j-maven-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>l4j-exe</id>
|
||||
<phase>package</phase>
|
||||
<goals><goal>launch4j</goal></goals>
|
||||
<configuration>
|
||||
<headerType>console</headerType>
|
||||
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
|
||||
<outfile>${project.build.directory}/workutils.exe</outfile>
|
||||
<dontWrapJar>false</dontWrapJar>
|
||||
<classPath>
|
||||
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
|
||||
</classPath>
|
||||
<jre>
|
||||
<minVersion>1.8.0</minVersion>
|
||||
<opts>
|
||||
<opt>-Dfile.encoding=UTF-8</opt>
|
||||
</opts>
|
||||
</jre>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.example.workutils;
|
||||
|
||||
import com.example.workutils.system.plugin.Plugin;
|
||||
import com.example.workutils.system.plugin.PluginManager;
|
||||
import com.example.workutils.system.support.WinConsole;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -23,6 +24,7 @@ public class WorkUtilsApplication implements CommandLineRunner {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
WinConsole.ensureUtf8();
|
||||
SpringApplication.run(WorkUtilsApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.workutils.system.support;
|
||||
|
||||
import com.sun.jna.platform.win32.Kernel32;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Windows 控制台工具:将控制台代码页切换为 UTF-8,
|
||||
* 确保 System.out / System.err 输出与 logback UTF-8 编码一致,
|
||||
* 解决中文乱码问题。
|
||||
*/
|
||||
public final class WinConsole {
|
||||
|
||||
private WinConsole() {}
|
||||
|
||||
/**
|
||||
* 如果运行在 Windows 下,将控制台输出代码页设置为 UTF-8 (65001),
|
||||
* 并重定向 System.out / System.err 为 UTF-8 编码。
|
||||
*/
|
||||
public static void ensureUtf8() {
|
||||
if (!System.getProperty("os.name", "").toLowerCase().contains("win")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Kernel32 kernel = Kernel32.INSTANCE;
|
||||
// 设置控制台输出/输入代码页为 UTF-8
|
||||
kernel.SetConsoleOutputCP(65001);
|
||||
kernel.SetConsoleCP(65001);
|
||||
|
||||
// 重定向 PrintStream,使 logback 和 System.out 都输出 UTF-8 字节
|
||||
System.setOut(new PrintStream(
|
||||
new FileOutputStream(FileDescriptor.out), true, StandardCharsets.UTF_8.name()));
|
||||
System.setErr(new PrintStream(
|
||||
new FileOutputStream(FileDescriptor.err), true, StandardCharsets.UTF_8.name()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// UTF-8 一定被支持,忽略
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ workutils:
|
||||
damaged-repos-file: "damaged_repos.cache"
|
||||
|
||||
logging:
|
||||
charset:
|
||||
console: UTF-8
|
||||
level:
|
||||
com.example.workutils: INFO
|
||||
org.springframework: WARN
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
title WorkUtils
|
||||
|
||||
java -Dfile.encoding=UTF-8 -jar "%~dp0target\workutils-0.0.1-SNAPSHOT.jar" %*
|
||||
|
||||
pause
|
||||
Reference in New Issue
Block a user