main
黄海 9 months ago
parent a17dcf143c
commit 63570d2b8d

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>dsProject</artifactId>
<groupId>com.dsideal</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dsBase</artifactId>
<name>dsBase</name>
<version>1.0</version>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.sql</include>
<include>**/*.class</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<finalName>dsRes</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>dsRes</finalName>
<transformers>
<transformer>
<mainClass>com.demo.common.DemoConfig</mainClass>
</transformer>
<transformer>
<resources />
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -81,7 +81,7 @@ public class CommonUtil {
public static List<String> getAllSql() throws IOException {
List<String> list = new ArrayList<>();
if (isRunInJar()) {
URL url = BaseApplication.class.getClassLoader().getResource("Sql/");
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();

@ -118,4 +118,54 @@
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!--不加此项,文件名中就会多出一个版本号-->
<finalName>dsBase</finalName>
<!--将resources做为资源目录拷贝到fatjar当中-->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
<!-- java21 保留参数名编译参数 -->
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!--打包fatjar的插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/resources/package.xml</descriptor> <!-- 配置文件路径 -->
</descriptors>
<archive>
<manifest>
<mainClass>com.dsideal.base.BaseApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -1,17 +1,17 @@
package com.dsideal.gw;
import cn.hutool.core.io.FileUtil;
import com.dsideal.gw.Contoller.IndexController;
import com.dsideal.gw.Handler.RouterHandler;
import com.dsideal.gw.Plugin.YamlProp;
import com.dsideal.gw.Util.CommonUtil;
import com.dsideal.gw.Util.LogBackLogFactory;
import com.jfinal.config.*;
import com.jfinal.kit.Prop;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import lombok.SneakyThrows;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.util.*;
public class GwApplication extends JFinalConfig {
@ -110,11 +110,10 @@ public class GwApplication extends JFinalConfig {
/**
* jfinal
*/
@SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
String path = Objects.requireNonNull(GwApplication.class.getClassLoader().getResource("logo.txt")).getPath();
File file = new File(path);
System.out.println(FileUtil.readUtf8String(file));
System.out.println(CommonUtil.txt2String("logo.txt"));
}
}

@ -1,23 +1,103 @@
package com.dsideal.gw.Util;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import org.apache.commons.codec.binary.Base64;
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.regex.Matcher;
import java.util.regex.Pattern;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@SuppressWarnings("unchecked")
public class CommonUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static final Logger log = LoggerFactory.getLogger(CommonUtil.class);
/**
* jar
*
* @return /
*/
public static boolean isRunInJar() {
String resourcePath = "/" + CommonUtil.class.getPackageName().replace(".", "/");
URL url = CommonUtil.class.getResource(resourcePath);
if (url.getProtocol().equals("jar")) {
return true;
}
return false;
}
/**
* jar
*
* @param path
* @return
* @throws IOException
*/
public static String txt2String(String path) throws IOException {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null;
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
}
/**
* sqllist
*
* @return
*/
public static List<String> getAllSql() throws IOException {
List<String> 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<JarEntry> 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;
}
/**
*

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<!-- 最终打包文件的后缀,格式为 ${fileName}-bin -->
<id>bin</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>zip</format>
</formats>
<!-- 把依赖的jar包打包进zip的lib目录下-->
<dependencySets>
<dependencySet>
<!-- 不使用项目的artifact -->
<useProjectArtifact>false</useProjectArtifact>
<!-- 打包进zip文件下的lib目录中 -->
<outputDirectory>lib</outputDirectory>
<!-- 第三方jar不要解压 -->
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<!-- 文件配置 -->
<fileSets>
<!-- 把项目的配置文件打包进zip包的config目录下 -->
<fileSet>
<!-- 配置项目中需要被打包的文件的存储路径 -->
<directory>${project.basedir}/src/main/resources/${env}</directory>
<outputDirectory>/config</outputDirectory>
<includes>
<!-- 可以指定单个文件 -->
<!--<include>project.config</include>-->
<!-- 可以直接指定所有文件 -->
<include>*.*</include>
</includes>
</fileSet>
<!-- 把项目的配置文件打包进zip包的根目录下 -->
<fileSet>
<directory>${project.basedir}/src/main/resources/${env}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>scf*.xml</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来根目录下的jar文件打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来的jar文件夹下的jar文件去除第三方jar打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}/jar</directory>
<outputDirectory></outputDirectory>
<excludes>
<exclude>lib/*.jar</exclude>
</excludes>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>

@ -266,11 +266,15 @@
</dependency>
</dependencies>
<build>
<!--不加此项,文件名中就会多出一个版本号-->
<finalName>dsBase</finalName>
<!--将resources做为资源目录拷贝到fatjar当中-->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -284,6 +288,31 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!--打包fatjar的插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/resources/package.xml</descriptor> <!-- 配置文件路径 -->
</descriptors>
<archive>
<manifest>
<mainClass>com.dsideal.base.BaseApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -4,6 +4,7 @@ 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.*;
@ -15,8 +16,10 @@ 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 {
@ -79,6 +82,7 @@ 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"),
@ -107,18 +111,13 @@ public class ResApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
//遍历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());
}
//加载所有的sql文件
List<String> list = CommonUtil.getAllSql();
for (String sqlFile : list) {
masterArp.addSqlTemplate(sqlFile);
slaveArp.addSqlTemplate(sqlFile);
}
//加载
me.add(masterArp);
me.add(slaveArp);
@ -168,11 +167,10 @@ public class ResApplication extends JFinalConfig {
/**
* jfinal
*/
@SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
String path = ResApplication.class.getClassLoader().getResource("logo.txt").getPath();
File file = new File(path);
System.out.println(FileUtil.txt2String(file));
System.out.println(CommonUtil.txt2String("logo.txt"));
}
}

@ -2,6 +2,7 @@ package com.dsideal.resource.Util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
@ -11,9 +12,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -21,7 +27,84 @@ import java.util.regex.Pattern;
public class CommonUtil {
//在独立的main函数中使用下面的方式进行声明logback对象
private static final Logger log = LoggerFactory.getLogger(CommonUtil.class);
/**
* jar
*
* @return /
*/
public static boolean isRunInJar() {
String resourcePath = "/" + CommonUtil.class.getPackageName().replace(".", "/");
URL url = CommonUtil.class.getResource(resourcePath);
if (url.getProtocol().equals("jar")) {
return true;
}
return false;
}
/**
* jar
*
* @param path
* @return
* @throws IOException
*/
public static String txt2String(String path) throws IOException {
InputStream is = CommonUtil.class.getClassLoader().getResourceAsStream(path);
BufferedInputStream bis = null;
StringBuilder sb = new StringBuilder();
try {
bis = new BufferedInputStream(is);
byte[] temp = new byte[1024];
int len;
while ((len = bis.read(temp)) != -1) {
sb.append(new String(temp, 0, len, StandardCharsets.UTF_8));
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
return sb.toString();
}
/**
* sqllist
*
* @return
*/
public static List<String> getAllSql() throws IOException {
List<String> 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<JarEntry> 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;
}
/**
*

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<!-- 最终打包文件的后缀,格式为 ${fileName}-bin -->
<id>bin</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>zip</format>
</formats>
<!-- 把依赖的jar包打包进zip的lib目录下-->
<dependencySets>
<dependencySet>
<!-- 不使用项目的artifact -->
<useProjectArtifact>false</useProjectArtifact>
<!-- 打包进zip文件下的lib目录中 -->
<outputDirectory>lib</outputDirectory>
<!-- 第三方jar不要解压 -->
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<!-- 文件配置 -->
<fileSets>
<!-- 把项目的配置文件打包进zip包的config目录下 -->
<fileSet>
<!-- 配置项目中需要被打包的文件的存储路径 -->
<directory>${project.basedir}/src/main/resources/${env}</directory>
<outputDirectory>/config</outputDirectory>
<includes>
<!-- 可以指定单个文件 -->
<!--<include>project.config</include>-->
<!-- 可以直接指定所有文件 -->
<include>*.*</include>
</includes>
</fileSet>
<!-- 把项目的配置文件打包进zip包的根目录下 -->
<fileSet>
<directory>${project.basedir}/src/main/resources/${env}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>scf*.xml</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来根目录下的jar文件打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来的jar文件夹下的jar文件去除第三方jar打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}/jar</directory>
<outputDirectory></outputDirectory>
<excludes>
<exclude>lib/*.jar</exclude>
</excludes>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Loading…
Cancel
Save