Browse Source

项目启动优化

zhanghaijun 2 years ago
parent
commit
4190877ca7

+ 27 - 25
pom.xml

@@ -132,27 +132,29 @@
         </plugins>
         </plugins>
         <pluginManagement>
         <pluginManagement>
             <plugins>
             <plugins>
+                <!--拷贝依赖到jar外面的lib目录-->
                 <plugin>
                 <plugin>
                     <groupId>org.springframework.boot</groupId>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
                     <configuration>
                     <configuration>
-                        <executable>true</executable>
+                        <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                         <layout>ZIP</layout>
                         <layout>ZIP</layout>
                         <includes>
                         <includes>
                             <include>
                             <include>
                                 <groupId>top.haijunit</groupId>
                                 <groupId>top.haijunit</groupId>
-                                <artifactId>train-common</artifactId>
+                                <artifactId>train-common-core</artifactId>
                             </include>
                             </include>
                         </includes>
                         </includes>
-                        <excludes>
-                            <exclude>
-                                <groupId>org.projectlombok</groupId>
-                                <artifactId>lombok</artifactId>
-                            </exclude>
-                        </excludes>
                     </configuration>
                     </configuration>
+                    <executions>
+                        <execution>
+                            <id>repackage</id>
+                            <goals>
+                                <goal>repackage</goal>
+                            </goals>
+                        </execution>
+                    </executions>
                 </plugin>
                 </plugin>
-                <!--拷贝依赖到jar外面的lib目录-->
                 <plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-dependency-plugin</artifactId>
                     <artifactId>maven-dependency-plugin</artifactId>
@@ -175,22 +177,22 @@
                     <plugin>
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-assembly-plugin</artifactId>
                         <artifactId>maven-assembly-plugin</artifactId>
-                    <version>3.3.0</version>
-                    <configuration>
-                        <appendAssemblyId>false</appendAssemblyId>
-                        <descriptors>
-                            <descriptor>src/assembly/assembly.xml</descriptor>
-                        </descriptors>
-                        <outputDirectory>target</outputDirectory>
-                    </configuration>
-                    <executions>
-                        <execution>
-                            <phase>package</phase>
-                            <goals>
-                                <goal>single</goal>
-                            </goals>
-                        </execution>
-                    </executions>
+                        <version>3.3.0</version>
+                        <configuration>
+                            <appendAssemblyId>false</appendAssemblyId>
+                            <descriptors>
+                                <descriptor>src/assembly/assembly.xml</descriptor>
+                            </descriptors>
+                            <outputDirectory>target</outputDirectory>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>single</goal>
+                                </goals>
+                            </execution>
+                        </executions>
                 </plugin>
                 </plugin>
             </plugins>
             </plugins>
         </pluginManagement>
         </pluginManagement>

+ 1 - 1
train-common/train-common-core/src/main/java/top/haijunit/common/config/LicenseFilter.java

@@ -28,7 +28,7 @@ public class LicenseFilter implements Filter {
             response.setContentType("application/json");
             response.setContentType("application/json");
             response.setCharacterEncoding("UTF-8");
             response.setCharacterEncoding("UTF-8");
             PrintWriter writer = response.getWriter();
             PrintWriter writer = response.getWriter();
-            writer.write(JSONUtil.toJsonStr(ResultData.fail("插件授权已过期,请联系管理员")));
+            writer.write(JSONUtil.toJsonStr(ResultData.fail("插件授权已过期,请联系管理员","")));
             return;
             return;
         }
         }
         chain.doFilter(request, response);
         chain.doFilter(request, response);

+ 7 - 7
train-common/train-common-core/src/main/java/top/haijunit/common/utils/HttpUtils.java

@@ -27,35 +27,35 @@ public class HttpUtils {
     private static final String CONTENT_TYPE_FORM = "multipart/form-data";
     private static final String CONTENT_TYPE_FORM = "multipart/form-data";
 
 
     /** GET请求 */
     /** GET请求 */
-    public static ResultData get(String url) {
+    public static ResultData<String> get(String url) {
         return HandleResponse(url, HttpRequest.get(url).timeout(TIME_OUT_MILLISECONDS).execute());
         return HandleResponse(url, HttpRequest.get(url).timeout(TIME_OUT_MILLISECONDS).execute());
     }
     }
 
 
     /** POST请求 */
     /** POST请求 */
-    public ResultData post(String url, Object body) {
+    public ResultData<String> post(String url, Object body) {
         return post(url, body, CONTENT_TYPE_JSON);
         return post(url, body, CONTENT_TYPE_JSON);
     }
     }
 
 
     /** POST Form 请求 */
     /** POST Form 请求 */
-    public ResultData postByForm(String url, Object body) {
+    public ResultData<String> postByForm(String url, Object body) {
         return post(url, body, CONTENT_TYPE_FORM);
         return post(url, body, CONTENT_TYPE_FORM);
     }
     }
 
 
     /** POST请求 */
     /** POST请求 */
-    public ResultData post(String url, Object body, String content) {
+    public ResultData<String> post(String url, Object body, String content) {
         String bodyStr = JSONUtil.toJsonStr(body);
         String bodyStr = JSONUtil.toJsonStr(body);
         log.info("HttpUtils POST. url={},bodyStr={}", url, bodyStr);
         log.info("HttpUtils POST. url={},bodyStr={}", url, bodyStr);
         HttpResponse response = HttpRequest.post(url).body(bodyStr, StrUtil.blankToDefault(content, CONTENT_TYPE_JSON)).timeout(TIME_OUT_MILLISECONDS).execute();
         HttpResponse response = HttpRequest.post(url).body(bodyStr, StrUtil.blankToDefault(content, CONTENT_TYPE_JSON)).timeout(TIME_OUT_MILLISECONDS).execute();
         return HandleResponse(url, response);
         return HandleResponse(url, response);
     }
     }
 
 
-    private ResultData HandleResponse(String url, HttpResponse response) {
+    private ResultData<String> HandleResponse(String url, HttpResponse response) {
         if (!response.isOk()) {
         if (!response.isOk()) {
             log.error("HttpUtils 响应失败. url={},response={}", url, response.getStatus());
             log.error("HttpUtils 响应失败. url={},response={}", url, response.getStatus());
-            return ResultData.fail("http响应失败,状态码:" + response.getStatus());
+            return ResultData.fail("http响应失败,状态码:" + response.getStatus(),"");
         }
         }
         log.info("HttpUtils 响应成功. url={},result={}", url, response.body());
         log.info("HttpUtils 响应成功. url={},result={}", url, response.body());
         JSONObject result = JSONUtil.parseObj(response.body());
         JSONObject result = JSONUtil.parseObj(response.body());
-        return new ResultData(Convert.toInt(result.get("resp_code"), ResultData.CODE_SUCCESS), Convert.toStr(result.get("resp_msg"), ""), Convert.toLong(result.get("time_stamp"), 0L));
+        return new ResultData<>(Convert.toInt(result.get("resp_code"), ResultData.CODE_SUCCESS), Convert.toStr(result.get("resp_msg"), ""), Convert.toLong(result.get("time_stamp"), 0L), "");
     }
     }
 }
 }

+ 1 - 1
train-server/src/assembly/bin/run.bat

@@ -6,7 +6,7 @@ for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
 :: Change directory to the parent directory of the script
 :: Change directory to the parent directory of the script
 cd /d "%SCRIPT_DIR%"
 cd /d "%SCRIPT_DIR%"
 
 
-start /B /MIN cmd /C stop.bat 8080
+start /B /MIN cmd /C stop.bat 8086
 timeout /t 1 /nobreak
 timeout /t 1 /nobreak
 start /MIN cmd /C start.bat > NUL 2>&1
 start /MIN cmd /C start.bat > NUL 2>&1
 echo Jar程序已在后台运行。
 echo Jar程序已在后台运行。

+ 3 - 3
train-server/src/assembly/bin/start-dev.bat

@@ -16,8 +16,8 @@ if errorlevel 1 (
     echo Please install Java and try again.
     echo Please install Java and try again.
     exit /b 1
     exit /b 1
 )
 )
-if not exist "plugins.jar" (
-    echo The file plugins.jar does not exist.
+if not exist "train-server.jar" (
+    echo The file train-server.jar does not exist.
     exit /b 1
     exit /b 1
 )
 )
 if not exist "./conf/application.yml" (
 if not exist "./conf/application.yml" (
@@ -29,6 +29,6 @@ if not exist "lib" (
     exit /b 1
     exit /b 1
 )
 )
 :: rest of your script
 :: rest of your script
-%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml
+%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar train-server.jar --spring.config.location=./conf/application.yml
 
 
 pause
 pause

+ 5 - 6
train-server/src/assembly/bin/start.bat

@@ -7,17 +7,16 @@ for %%I in ("%~dp0.") do set "SCRIPT_DIR=%%~fI"
 cd /d "%SCRIPT_DIR%\.."
 cd /d "%SCRIPT_DIR%\.."
 
 
 :: Check if Java is installed
 :: Check if Java is installed
-REM set "javaPath=C:\path\to\java\bin\java.exe"
-set "javaPath=java"
-set "plugin.dev=false"
+set "javaPath=D:\windows\app\Java\jdk-17.0.8\bin\java.exe"
+REM set "javaPath=java"
 %javaPath% -version >nul 2>&1
 %javaPath% -version >nul 2>&1
 if errorlevel 1 (
 if errorlevel 1 (
     echo Java is not installed or not found.
     echo Java is not installed or not found.
     echo Please install Java and try again.
     echo Please install Java and try again.
     exit /b 1
     exit /b 1
 )
 )
-if not exist "plugins.jar" (
-    echo The file plugins.jar does not exist.
+if not exist "train-server.jar" (
+    echo The file train-server.jar does not exist.
     exit /b 1
     exit /b 1
 )
 )
 if not exist "./conf/application.yml" (
 if not exist "./conf/application.yml" (
@@ -29,6 +28,6 @@ if not exist "lib" (
     exit /b 1
     exit /b 1
 )
 )
 :: rest of your script
 :: rest of your script
-%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml
+%javaPath% -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar train-server.jar --spring.config.location=./conf/application.yml
 
 
 pause
 pause

+ 4 - 4
train-server/src/assembly/bin/start.sh

@@ -13,9 +13,9 @@ if ! type java >/dev/null 2>&1; then
     exit 1
     exit 1
 fi
 fi
 
 
-# Check if plugins.jar file exists
-if [ ! -f "plugins.jar" ]; then
-    echo The file plugins.jar does not exist.
+# Check if train-server.jar file exists
+if [ ! -f "train-server.jar" ]; then
+    echo The file train-server.jar does not exist.
     exit 1
     exit 1
 fi
 fi
 
 
@@ -32,4 +32,4 @@ if [ ! -d "lib" ]; then
 fi
 fi
 
 
 JAVA_OPTS=" -server -Xmx2g -Xms2g -Xmn256m"
 JAVA_OPTS=" -server -Xmx2g -Xms2g -Xmn256m"
-exec java $JAVA_OPTS -Duser.timezone=Asia/Shanghai -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar plugins.jar --spring.config.location=./conf/application.yml
+exec java $JAVA_OPTS -Duser.timezone=Asia/Shanghai -Djava.security.egd=file:/dev/./urandom -Dloader.path=./lib -jar train-server.jar --spring.config.location=./conf/application.yml

+ 1 - 1
train-server/src/assembly/bin/stop.bat

@@ -6,7 +6,7 @@ setlocal
 REM 设置默认端口号
 REM 设置默认端口号
 set "port=%1"
 set "port=%1"
 if "%port%"=="" (
 if "%port%"=="" (
-    set "port=8080"
+    set "port=8086"
 )
 )
 echo 检测端口:%port%
 echo 检测端口:%port%
 REM 使用 netstat 和 findstr 命令获取占用特定端口的进程信息
 REM 使用 netstat 和 findstr 命令获取占用特定端口的进程信息

+ 1 - 1
train-server/src/main/resources/application.yml

@@ -1,5 +1,5 @@
 server:
 server:
-  port: 8080
+  port: 8086
   servlet:
   servlet:
     encoding:
     encoding:
       charset: UTF-8
       charset: UTF-8