diff --git a/yyets-history/pom.xml b/yyets-history/pom.xml
index 59cba98..7637acd 100644
--- a/yyets-history/pom.xml
+++ b/yyets-history/pom.xml
@@ -21,10 +21,6 @@
org.springframework.boot
spring-boot-starter
-
- org.springframework.boot
- spring-boot-starter-jdbc
-
com.alibaba
fastjson
@@ -53,16 +49,6 @@
hutool-all
5.7.17
-
- org.apache.commons
- commons-compress
- 1.21
-
-
- org.tukaani
- xz
- 1.9
-
com.github.pagehelper
pagehelper-spring-boot-starter
@@ -110,7 +96,7 @@
src/main/resources
- static/yyets.7z
+ static/yyets.zip
diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java
index 93e0347..908a505 100644
--- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java
+++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/YyetsHistoryApplication.java
@@ -3,7 +3,6 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartFinish;
import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartPrepare;
@SpringBootApplication
@@ -12,7 +11,6 @@ public class YyetsHistoryApplication {
public static void main(String[] args) {
onStartPrepare(args);
SpringApplication.run(YyetsHistoryApplication.class, args);
- onStartFinish();
}
}
diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppConfig.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppConfig.java
index 3315958..c2a4ac2 100644
--- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppConfig.java
+++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppConfig.java
@@ -3,7 +3,7 @@
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.net.URLDecoder;
-import cn.hutool.extra.compress.extractor.SevenZExtractor;
+import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.spring.EnableSpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
@@ -16,7 +16,6 @@
import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
-import java.nio.file.StandardCopyOption;
@Slf4j
@@ -32,12 +31,12 @@ public YyetsHistoryProperties yyetsHistoryConfig() {
@Bean
public DataSource dataSource(DataSourceProperties properties) {
- extractDb7zFile();
+ uncompressDbFile();
return DataSourceBuilder.create().driverClassName(properties.getDriverClassName())
.url(properties.getUrl()).build();
}
- private void extractDb7zFile() {
+ private void uncompressDbFile() {
URL dbResource = getClass().getResource("/static/yyets.db");
if (dbResource != null) {
log.info("检测到数据源文件: {}", URLDecoder.decode(dbResource.getPath(), StandardCharsets.UTF_8));
@@ -50,30 +49,29 @@ private void extractDb7zFile() {
projectPath = projectPath + moduleName;
}
String staticResourcePath = projectPath + "/src/main/resources/static/";
- String dbFilePath = staticResourcePath + "yyets.db";
- File dbFile = new File(dbFilePath);
+ File dbFile = new File(staticResourcePath + "yyets.db");
if (dbFile.exists()) {
throw new IllegalStateException("请重新编译项目");
}
- String db7zFilePath = staticResourcePath + "yyets.7z";
- File db7zFile = new File(db7zFilePath);
- if (!db7zFile.exists()) {
- throw new IORuntimeException("数据源文件缺失并且无法找到压缩包: " + db7zFilePath);
+ String zipFilePath = staticResourcePath + "yyets.zip";
+ File zipFile = new File(staticResourcePath + "yyets.zip");
+ if (!zipFile.exists()) {
+ throw new IORuntimeException("数据源文件缺失并且无法找到压缩包: " + zipFilePath);
}
- log.info("开始解压数据源文件: {}", db7zFilePath);
- try (SevenZExtractor sevenZExtractor = new SevenZExtractor(db7zFile)) {
- sevenZExtractor.extract(new File(staticResourcePath));
+ log.info("开始解压数据源文件: {}", zipFilePath);
+ try {
+ ZipUtil.unzip(zipFile, new File(staticResourcePath));
if (dbFile.exists()) {
- log.info("数据源文件自动解压完成: {}", dbFilePath);
+ log.info("数据源文件自动解压完成: {}", dbFile.getPath());
String classPath = getClass().getResource("/static").getPath();
classPath = URLDecoder.decode(classPath, StandardCharsets.UTF_8);
- FileUtil.copyFile(dbFile, new File(classPath), StandardCopyOption.REPLACE_EXISTING);
+ FileUtil.copyFile(dbFile, new File(classPath));
log.info("复制数据源文件至classpath: {}", classPath);
} else {
- throw new IORuntimeException("未知的解压异常: " + db7zFilePath);
+ throw new IORuntimeException("未知的解压异常: " + zipFilePath);
}
} catch (Exception e) {
- String msg = "数据源文件自动解压失败,请手动解压文件: resources/static/yyets.7z";
+ String msg = "数据源文件自动解压失败,请手动解压文件: " + zipFilePath;
throw new IORuntimeException(msg, e);
}
}
diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java
new file mode 100644
index 0000000..3fbe42d
--- /dev/null
+++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/config/AppRunner.java
@@ -0,0 +1,16 @@
+package com.zhangjiashuai.yyetshistory.config;
+
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static com.zhangjiashuai.yyetshistory.util.NativeOperationUtils.onStartFinish;
+
+@Configuration
+public class AppRunner implements ApplicationRunner {
+
+ @Override
+ public void run(ApplicationArguments args) {
+ onStartFinish();
+ }
+}
diff --git a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java
index 116f172..1ff6142 100644
--- a/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java
+++ b/yyets-history/src/main/java/com/zhangjiashuai/yyetshistory/util/NativeConfigUtil.java
@@ -119,7 +119,7 @@ static void loadCommandLineArgs(String[] args) {
static String getHost() {
String host = StrUtil.toStringOrNull(getProperty("yyets-history.host"));
- return StrUtil.isNotBlank(host) ? StrUtil.trim(host) : DEFAULT_HOST;
+ return StrUtil.isNotBlank(host) ? host.trim() : DEFAULT_HOST;
}
static int getPort() {
diff --git a/yyets-history/src/main/resources/static/yyets.7z b/yyets-history/src/main/resources/static/yyets.zip
similarity index 71%
rename from yyets-history/src/main/resources/static/yyets.7z
rename to yyets-history/src/main/resources/static/yyets.zip
index cb324b9..708f298 100644
Binary files a/yyets-history/src/main/resources/static/yyets.7z and b/yyets-history/src/main/resources/static/yyets.zip differ
diff --git a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java
index b8e1d5a..6eaf503 100644
--- a/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java
+++ b/yyets-history/src/test/java/com/zhangjiashuai/yyetshistory/SimpleTest.java
@@ -4,7 +4,7 @@
import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.swing.DesktopUtil;
import cn.hutool.core.swing.clipboard.ClipboardUtil;
-import cn.hutool.extra.compress.extractor.SevenZExtractor;
+import cn.hutool.core.util.ZipUtil;
import com.zhangjiashuai.yyetshistory.util.NativeOperationUtils;
import org.junit.jupiter.api.Test;
@@ -48,16 +48,18 @@ public void testLinkedHashSet() {
}
@Test
- public void testExtract7z() {
+ public void testExtractZip() {
String projectPath = System.getProperty("user.dir");
String staticResourcePath = projectPath + "/src/main/resources/static/";
- String db7zFilename = "yyets.7z";
- File db7zFile = new File(staticResourcePath + db7zFilename);
- System.out.println(db7zFile.exists());
- try (SevenZExtractor sevenZExtractor = new SevenZExtractor(db7zFile)) {
- sevenZExtractor.extract(new File(staticResourcePath));
- }
+ String dbZipFilename = "yyets.zip";
+ File dbZipFile = new File(staticResourcePath + dbZipFilename);
+ Assert.isTrue(dbZipFile.exists());
File dbFile = new File(staticResourcePath + "yyets.db");
+ if(!dbFile.exists()) {
+ long start = System.currentTimeMillis();
+ ZipUtil.unzip(dbZipFile, new File(staticResourcePath));
+ System.out.println("解压完成,耗时: " + (System.currentTimeMillis() - start));
+ }
Assert.isTrue(dbFile.exists());
}