Browse Source

fix:解决学生行为数据下载失败的问题,修改打包方式

wuzilong 7 months ago
parent
commit
091edab002
2 changed files with 50 additions and 0 deletions
  1. 48 0
      pom.xml
  2. 2 0
      src/main/java/com/njuzr/eaibackend/EaiBackendApplication.java

+ 48 - 0
pom.xml

@@ -222,6 +222,52 @@
 
     <build>
         <plugins>
+            <!-- 使用 maven-shade-plugin 打包所有依赖 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>3.5.1</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            <!-- 创建可执行的 JAR -->
+                            <transformers>
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>com.njuzr.eaibackend.EaiBackendApplication</mainClass>
+                                </transformer>
+                                <!-- 合并 META-INF/spring.factories 文件 -->
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
+                                    <resource>META-INF/spring.factories</resource>
+                                </transformer>
+                                <!-- 合并 META-INF/spring.components 文件 -->
+                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
+                                    <resource>META-INF/spring.components</resource>
+                                </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>
+                            <!-- 生成依赖简化后的文件 -->
+                            <createDependencyReducedPom>false</createDependencyReducedPom>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <!-- 跳过 spring-boot-maven-plugin,避免冲突 -->
+            <!--
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
@@ -234,6 +280,8 @@
                     </excludes>
                 </configuration>
             </plugin>
+            -->
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>

+ 2 - 0
src/main/java/com/njuzr/eaibackend/EaiBackendApplication.java

@@ -9,6 +9,8 @@ import org.springframework.cache.annotation.EnableCaching;
 public class EaiBackendApplication {
 
     public static void main(String[] args) {
+        // 设置 headless 模式,解决 Linux 服务器下 AWT 相关问题
+        System.setProperty("java.awt.headless", "true");
         SpringApplication.run(EaiBackendApplication.class, args);
     }