From 5982956b3e02bf40ff9679aa1a86a7281708ce66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com>
Date: Fri, 18 Oct 2024 13:18:55 +0800
Subject: [PATCH] 'commit'
---
dsBase/Dockerfile | 16 ++--
dsBase/pom.xml | 75 ++-----------------
.../com/dsideal/base/BaseApplication.java | 54 ++++++++++---
dsBase/生成依赖jar.bat | 8 ++
dsGw/Dockerfile | 17 ++---
dsGw/pom.xml | 46 ------------
.../java/com/dsideal/gw/Util/CommonUtil.java | 43 -----------
dsGw/生成依赖jar.bat | 8 ++
dsRes/Dockerfile | 17 ++---
dsRes/pom.xml | 37 ---------
.../com/dsideal/resource/ResApplication.java | 30 ++++----
.../src/main/java/com/dsideal/Publish.java | 3 +-
.../java/com/dsideal/Utils/PublishUtil.java | 55 +++++++++-----
13 files changed, 141 insertions(+), 268 deletions(-)
create mode 100644 dsBase/生成依赖jar.bat
create mode 100644 dsGw/生成依赖jar.bat
diff --git a/dsBase/Dockerfile b/dsBase/Dockerfile
index 7426bead..72152675 100644
--- a/dsBase/Dockerfile
+++ b/dsBase/Dockerfile
@@ -6,19 +6,17 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量,TZ代表Time Zone
ENV TZ=Asia/Shanghai
-# 声明变量
-ENV file_name="dsBase-jar-with-dependencies.jar"
-
# 让容器内部正常显示中文
-ENV LANG=C.UTF-8
+ENV LANG C.UTF-8
-# 将jar包复制到容器的/root目录下
-COPY $file_name /root/$file_name
+# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
+COPY ./lib /root/lib
+COPY ./target /root/target
#设置这个环境变量后,您可以在Docker容器中启动Java应用程序时使用这些参数。
-ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
+ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
-ENV WORKING_ENV="dev"
+ENV WORKING_ENV="pro"
-ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
+ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.base.BaseApplication" ]
diff --git a/dsBase/pom.xml b/dsBase/pom.xml
index b9a9dc9d..acb693a5 100644
--- a/dsBase/pom.xml
+++ b/dsBase/pom.xml
@@ -55,6 +55,12 @@
minio
${minio.version}
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.1
+
net.sf.json-lib
@@ -207,43 +213,13 @@
jjwt
0.7.0
-
- javax.xml.bind
- jaxb-api
- 2.3.0
-
-
- com.sun.xml.bind
- jaxb-impl
- 2.3.0
-
-
- com.sun.xml.bind
- jaxb-core
- 2.3.0
-
-
- javax.activation
- activation
- 1.1.1
-
-
-
- dsBase
-
-
-
- src/main/resources
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
- ${maven-compiler-plugin.version}
+ 3.6.1
21
21
@@ -252,43 +228,6 @@
-parameters
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- ${maven-assembly-plugin.version}
-
-
- jar-with-dependencies
-
-
-
- com.dsideal.base.BaseApplication
-
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${maven-jar-plugin.version}
-
-
- default-jar
- none
-
-
-
\ No newline at end of file
diff --git a/dsBase/src/main/java/com/dsideal/base/BaseApplication.java b/dsBase/src/main/java/com/dsideal/base/BaseApplication.java
index 9736ac37..65100e57 100644
--- a/dsBase/src/main/java/com/dsideal/base/BaseApplication.java
+++ b/dsBase/src/main/java/com/dsideal/base/BaseApplication.java
@@ -17,10 +17,11 @@ import com.dsideal.base.StudentYd.Controller.StudentYdController;
import com.dsideal.base.Teacher.Controller.TeacherController;
import com.dsideal.base.TeacherYd.Controller.TeacherYdController;
import com.dsideal.base.Tools.Controller.excelConvertController;
-import com.dsideal.base.Util.CommonUtil;
+import com.dsideal.base.Util.FileUtil;
import com.dsideal.base.Util.LogBackLogFactory;
import com.dsideal.base.Util.PkUtil;
import com.jfinal.config.*;
+import com.jfinal.kit.PathKit;
import com.jfinal.kit.Prop;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
@@ -29,8 +30,9 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
-import lombok.SneakyThrows;
-import java.util.List;
+
+import java.io.File;
+
public class BaseApplication extends JFinalConfig {
public static String getEnvPrefix() {
@@ -104,16 +106,37 @@ public class BaseApplication extends JFinalConfig {
}
- @SneakyThrows
+ /**
+ * 配置插件
+ */
+ private String connectionTestQuery = "select 1";
+ // 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
+ private int maxPoolSize = 10;
+ // 一个连接 idle 状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
+ private long idleTimeoutMs = 600000;
+ private long maxLifetimeMs = 1800000;
+ // 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException, 缺省:30秒
+ private long connectionTimeoutMs = 30000;
+
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
+ masterPlugin.setConnectionTestQuery(connectionTestQuery);
+ masterPlugin.setConnectionTimeout(connectionTimeoutMs);
+ masterPlugin.setIdleTimeout(idleTimeoutMs);
+ masterPlugin.setMaxLifetime(maxLifetimeMs);
+ masterPlugin.setMaximumPoolSize(maxPoolSize);
String jdbcUrlSlave = PropKit.get("mysql.jdbcUrlSlave");
if (StrKit.isBlank(jdbcUrlSlave)) jdbcUrlSlave = PropKit.get("mysql.jdbcUrl");
HikariCpPlugin slavePlugin = new HikariCpPlugin(jdbcUrlSlave, PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
+ slavePlugin.setConnectionTestQuery(connectionTestQuery);
+ slavePlugin.setConnectionTimeout(connectionTimeoutMs);
+ slavePlugin.setIdleTimeout(idleTimeoutMs);
+ slavePlugin.setMaxLifetime(maxLifetimeMs);
+ slavePlugin.setMaximumPoolSize(maxPoolSize);
me.add(masterPlugin);
me.add(slavePlugin);
@@ -123,11 +146,17 @@ public class BaseApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
- //加载所有的sql文件
- List list = CommonUtil.getAllSql();
- for (String sqlFile : list) {
- masterArp.addSqlTemplate(sqlFile);
- slaveArp.addSqlTemplate(sqlFile);
+ //遍历sql目录下所有的sql文件
+ File sqlDir;
+ String basePath = PathKit.getRootClassPath();
+ sqlDir = new File(basePath + "/Sql");
+ File[] sqlFiles = sqlDir.listFiles();
+ for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
+ //只加载.sql文件
+ if (sqlFile.getName().indexOf(".sql") > 0) {
+ masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
+ slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
+ }
}
//加载
me.add(masterArp);
@@ -193,13 +222,16 @@ public class BaseApplication extends JFinalConfig {
/**
* 在jfinal启动完成后马上执行
*/
- @SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
- System.out.println(CommonUtil.txt2String("logo.txt"));
+ String path = BaseApplication.class.getClassLoader().getResource("logo.txt").getPath();
+ File file = new File(path);
+ System.out.println(FileUtil.txt2String(file));
+
//初始化人员主键序列
PkUtil.InitPersonNumPk();
+
//初始化组织机构主键序列
PkUtil.InitOrgNumPk();
}
diff --git a/dsBase/生成依赖jar.bat b/dsBase/生成依赖jar.bat
new file mode 100644
index 00000000..4ecb7b0d
--- /dev/null
+++ b/dsBase/生成依赖jar.bat
@@ -0,0 +1,8 @@
+mkdir lib
+cd lib
+del *.jar /q
+cd ..
+mvn -f pom.xml dependency:copy-dependencies -DoutputDirectory=lib
+
+@echo 黄海完成了!
+pause
diff --git a/dsGw/Dockerfile b/dsGw/Dockerfile
index bbf30a65..52e5119c 100644
--- a/dsGw/Dockerfile
+++ b/dsGw/Dockerfile
@@ -6,19 +6,18 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量,TZ代表Time Zone
ENV TZ=Asia/Shanghai
-# 声明变量
-ENV file_name="dsGw-jar-with-dependencies.jar"
-
# 让容器内部正常显示中文
-ENV LANG=C.UTF-8
+ENV LANG C.UTF-8
+
-# 将jar包复制到容器的/root目录下
-COPY $file_name /root/$file_name
+# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
+COPY ./lib /root/lib
+COPY ./target /root/target
#设置这个环境变量后,您可以在Docker容器中启动Java应用程序时使用这些参数。
-ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
+ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
-ENV WORKING_ENV="dev"
+ENV WORKING_ENV="pro"
-ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
+ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.gw.GwApplication" ]
diff --git a/dsGw/pom.xml b/dsGw/pom.xml
index cce70816..387fcd44 100644
--- a/dsGw/pom.xml
+++ b/dsGw/pom.xml
@@ -119,15 +119,6 @@
-
- dsGw
-
-
-
- src/main/resources
-
-
-
org.apache.maven.plugins
@@ -141,43 +132,6 @@
-parameters
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- ${maven-assembly-plugin.version}
-
-
- jar-with-dependencies
-
-
-
- com.dsideal.gw.GwApplication
-
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${maven-jar-plugin.version}
-
-
- default-jar
- none
-
-
-
diff --git a/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java b/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java
index 4c90fe83..684c8e72 100644
--- a/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java
+++ b/dsGw/src/main/java/com/dsideal/gw/Util/CommonUtil.java
@@ -1,21 +1,14 @@
package com.dsideal.gw.Util;
import cn.hutool.core.io.IoUtil;
-import com.jfinal.kit.PathKit;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.BufferedInputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.JarURLConnection;
import java.net.URL;
-import java.nio.charset.StandardCharsets;
import java.util.*;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
@SuppressWarnings("unchecked")
public class CommonUtil {
@@ -47,42 +40,6 @@ public class CommonUtil {
return IoUtil.read(is, "UTF-8");
}
- /**
- * 获取所有sql文件,并返回一个list集合
- *
- * @return
- */
- public static List getAllSql() throws IOException {
- List list = new ArrayList<>();
- if (isRunInJar()) {
- URL url = CommonUtil.class.getClassLoader().getResource("Sql/");
- String jarPath = url.toString().substring(0, url.toString().indexOf("!/") + 2);
- URL jarURL = new URL(jarPath);
- JarURLConnection jarCon = (JarURLConnection) jarURL.openConnection();
- JarFile jarFile = jarCon.getJarFile();
- Enumeration jarEntrys = jarFile.entries();
- while (jarEntrys.hasMoreElements()) {
- JarEntry entry = jarEntrys.nextElement();
- String name = entry.getName();
- if (name.startsWith("Sql/") && !entry.isDirectory()) {
- list.add(name);
- }
- }
- } else {//如果运行在文件系统中,直接加载sql文件
- //遍历sql目录下所有的sql文件
- File sqlDir;
- String basePath = PathKit.getRootClassPath();
- sqlDir = new File(basePath + "/Sql");
- File[] sqlFiles = sqlDir.listFiles();
- for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
- if (sqlFile.getName().indexOf(".sql") > 0) {//只加载.sql文件
- list.add("Sql/"+sqlFile.getName());
- }
- }
- }
- return list;
- }
-
/**
* 加签
*
diff --git a/dsGw/生成依赖jar.bat b/dsGw/生成依赖jar.bat
new file mode 100644
index 00000000..4ecb7b0d
--- /dev/null
+++ b/dsGw/生成依赖jar.bat
@@ -0,0 +1,8 @@
+mkdir lib
+cd lib
+del *.jar /q
+cd ..
+mvn -f pom.xml dependency:copy-dependencies -DoutputDirectory=lib
+
+@echo 黄海完成了!
+pause
diff --git a/dsRes/Dockerfile b/dsRes/Dockerfile
index 9d50a491..abf4212c 100644
--- a/dsRes/Dockerfile
+++ b/dsRes/Dockerfile
@@ -6,19 +6,18 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量,TZ代表Time Zone
ENV TZ=Asia/Shanghai
-# 声明变量
-ENV file_name="dsRes-jar-with-dependencies.jar"
-
# 让容器内部正常显示中文
-ENV LANG=C.UTF-8
+ENV LANG C.UTF-8
+
-# 将jar包复制到容器的/root目录下
-COPY $file_name /root/$file_name
+# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
+COPY ./lib /root/lib
+COPY ./target /root/target
#设置这个环境变量后,您可以在Docker容器中启动Java应用程序时使用这些参数。
-ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
+ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
-ENV WORKING_ENV="dev"
+ENV WORKING_ENV="pro"
-ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
+ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.resource.ResApplication" ]
diff --git a/dsRes/pom.xml b/dsRes/pom.xml
index 9bb06225..d48537d6 100644
--- a/dsRes/pom.xml
+++ b/dsRes/pom.xml
@@ -261,43 +261,6 @@
-parameters
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- ${maven-assembly-plugin.version}
-
-
- jar-with-dependencies
-
-
-
- com.dsideal.base.BaseApplication
-
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- ${maven-jar-plugin.version}
-
-
- default-jar
- none
-
-
-
\ No newline at end of file
diff --git a/dsRes/src/main/java/com/dsideal/resource/ResApplication.java b/dsRes/src/main/java/com/dsideal/resource/ResApplication.java
index 46541a17..d05fe15e 100644
--- a/dsRes/src/main/java/com/dsideal/resource/ResApplication.java
+++ b/dsRes/src/main/java/com/dsideal/resource/ResApplication.java
@@ -4,7 +4,6 @@ import com.dsideal.resource.Base.Controller.BaseController;
import com.dsideal.resource.Index.IndexController;
import com.dsideal.resource.Interceptor.*;
import com.dsideal.resource.Plugin.YamlProp;
-import com.dsideal.resource.Util.CommonUtil;
import com.dsideal.resource.Util.FileUtil;
import com.dsideal.resource.Util.LogBackLogFactory;
import com.jfinal.config.*;
@@ -16,10 +15,8 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
-import lombok.SneakyThrows;
import java.io.File;
-import java.util.List;
public class ResApplication extends JFinalConfig {
@@ -82,7 +79,6 @@ public class ResApplication extends JFinalConfig {
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException, 缺省:30秒
private long connectionTimeoutMs = 30000;
- @SneakyThrows
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
@@ -111,13 +107,18 @@ public class ResApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
- //加载所有的sql文件
- List list = CommonUtil.getAllSql();
- for (String sqlFile : list) {
- masterArp.addSqlTemplate(sqlFile);
- slaveArp.addSqlTemplate(sqlFile);
+ //遍历sql目录下所有的sql文件
+ File sqlDir;
+ String basePath = ResApplication.class.getResource("/").getPath();
+ sqlDir = new File(basePath + "/Sql");
+ File[] sqlFiles = sqlDir.listFiles();
+ for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
+ //只加载.sql文件
+ if (sqlFile.getName().indexOf(".sql") > 0) {
+ masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
+ slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
+ }
}
-
//加载
me.add(masterArp);
me.add(slaveArp);
@@ -138,6 +139,7 @@ public class ResApplication extends JFinalConfig {
//注册非空拦截器
me.add(new EmptyInterceptor());
+
//注册Ids检查是不是数字的检查器
me.add(new CheckIdsInterceptor());
@@ -149,9 +151,6 @@ public class ResApplication extends JFinalConfig {
//注册一个检查输入文本长度的拦截器
me.add(new LengthInterceptor());
-
- //注册JWT
- me.add(new JwtCheckInterceptor());
}
/**
@@ -164,10 +163,11 @@ public class ResApplication extends JFinalConfig {
/**
* 在jfinal启动完成后马上执行
*/
- @SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
- System.out.println(CommonUtil.txt2String("logo.txt"));
+ String path = ResApplication.class.getClassLoader().getResource("logo.txt").getPath();
+ File file = new File(path);
+ System.out.println(FileUtil.txt2String(file));
}
}
diff --git a/dsUtils/src/main/java/com/dsideal/Publish.java b/dsUtils/src/main/java/com/dsideal/Publish.java
index 1d102d55..2c14b168 100644
--- a/dsUtils/src/main/java/com/dsideal/Publish.java
+++ b/dsUtils/src/main/java/com/dsideal/Publish.java
@@ -50,7 +50,6 @@ public class Publish {
String basedir = new File(System.getProperty("user.dir")).getCanonicalPath();
workingPath = basedir + "\\" + projectBean.getDevProjectName() + "\\";
projectName = projectBean.getPublishProjectName();
- devProjectName= projectBean.getDevProjectName();
if (FileUtil.exist(workingPath + "lib")) {
localLibPath = workingPath + "lib\\";
}
@@ -61,7 +60,7 @@ public class Publish {
isStatic = true;
}
//开始打包
- Kv ret = PublishUtil.publish(projectName,devProjectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
+ Kv ret = PublishUtil.publish(projectName,isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
System.out.println("测试运行一下容器吧");
if (ret.getStr("project_port") != null) {
diff --git a/dsUtils/src/main/java/com/dsideal/Utils/PublishUtil.java b/dsUtils/src/main/java/com/dsideal/Utils/PublishUtil.java
index 2b14ea99..8f91a9ff 100644
--- a/dsUtils/src/main/java/com/dsideal/Utils/PublishUtil.java
+++ b/dsUtils/src/main/java/com/dsideal/Utils/PublishUtil.java
@@ -5,7 +5,6 @@ import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
-import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import java.io.*;
@@ -64,8 +63,12 @@ public class PublishUtil {
* docker tag 19a54d2204aa registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
* docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
*/
- public static Kv publish(String projectName, String devProjectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
-
+ public static Kv publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
+ //判断是不是有需要批处理的生成JAR的过程
+ String cmdPath = workingPath + "生成依赖jar.bat";
+ if (FileUtil.exist(cmdPath)) {
+ ExecBatchCmd(cmdPath);
+ }
System.out.println("正在生成" + projectName + "的镜像...");
//配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json";
@@ -101,24 +104,38 @@ public class PublishUtil {
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile");
}
- System.out.println("正在上传" + projectName + "的jar包...");
- //上传jar包
- String fatjarName = devProjectName + "-jar-with-dependencies.jar";
- String localFile = workingPath + "target/" + fatjarName;
- //获取项目端口
- String undertow_dev = workingPath.replace("\\","/") + "target/classes/undertow_dev.properties";
- List list=FileUtil.readLines(undertow_dev, "UTF-8");
- for (String line : list) {
- if (line.contains("undertow.port")) {
- String[] split = line.split("=");
- project_port = split[1];
- break;
+ if (!StrKit.isBlank(localLibPath)) {
+ System.out.println("正在创建lib目录...");
+ ssh.mkdir(remotePath + "lib");
+ //遍历lib目录下的文件
+ for (File file : FileUtil.loopFiles(localLibPath)) {
+ System.out.println("正在上传jar包:" + file.getName());
+ ssh.upload(file.getAbsolutePath(), remotePath + "lib/" + file.getName());
}
}
- if (FileUtil.exist(localFile)) {
- System.out.println("正在上传" + fatjarName + "...");
+
+ //打包target为zip
+ if (FileUtil.isDirectory(workingPath + "target")) {
+ String localFile = workingPath + "target.zip";
+ if (FileUtil.exist(localFile)) {
+ FileUtil.del(localFile);
+ }
+ System.out.println("正在上传target.zip...");
+ // 将目录打包成ZIP文件,不包含目录本身,只包含目录下的文件和子目录
+ ZipUtil.zip(workingPath + "target", localFile, true);
//上传
- ssh.upload(localFile, remotePath + fatjarName);
+ ssh.upload(localFile, remotePath + "target.zip");
+ //删除target.zip
+ FileUtil.del(localFile);
+ //解压缩
+ System.out.println("正在解压缩target.zip...");
+ ssh.exec("cd " + remotePath + " && unzip target.zip");
+ ssh.exec("cd " + remotePath + " && rm -rf target.zip");
+
+ //获取项目端口
+ String undertow_dev = remotePath + "target/classes/undertow_dev.properties";
+ String cmd = "grep '^undertow\\.port=' " + undertow_dev + " | awk -F'=' '{print $2}'";
+ project_port = ssh.exec(cmd).getStr("message").replace("[", "").replace("]", "");
}
//处理静态文件
@@ -133,7 +150,7 @@ public class PublishUtil {
break;
}
}
- localFile = workingPath.substring(0, pos) + "\\static.zip";
+ String localFile = workingPath.substring(0, pos) + "\\static.zip";
if (FileUtil.exist(localFile)) {
FileUtil.del(localFile);
}