原文地址:https://blog.csdn.net/qq_35280367/article/details/79741964

一、将Spring Boot项目打成JAR包

1.先选择项目的根目录 IDEA

如何Spring Boot项目打成JAR包以及WAR包方式

2.在命令窗口cmd中cd  项目路径→选中路径的磁盘

如何Spring Boot项目打成JAR包以及WAR包方式

3.输入Maven命令 mvn -Dmaven.test.Skip -U clean package

4.如果是Maven多层架构  会报错  找不到启动类

如何Spring Boot项目打成JAR包以及WAR包方式

[html] view plain copy
  1. 将启动类配置到web里的pom.xml中   
  2. <build>  
  3.         <plugins>  
  4.             <plugin>  
  5.                 <groupId>org.springframework.boot</groupId>  
  6.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  7.                 <configuration>  
  8.                     <mainClass>fristappdemo.FristAppDemoApplicationTests</mainClass>  
  9.                 </configuration>  
  10.             </plugin>  
  11.         </plugins>  
  12.     </build>  
[html] view plain copy
  1. 各层相互依赖  web→service→model
  2. <!--web里pom.xml-->  
  3.  <dependencies>  
  4.         <dependency>  
  5.             <groupId>com.xcy</groupId>  
  6.             <artifactId>persistence</artifactId>  
  7.             <version>0.0.1-SNAPSHOT</version>  
  8.         </dependency>  
  9.     </dependencies>  
  10. <!--service里pom.xml-->  
  11.  <dependencies>  
  12.         <dependency>  
  13.             <groupId>com.xcy</groupId>  
  14.             <artifactId>model</artifactId>  
  15.             <version>0.0.1-SNAPSHOT</version>  
  16.         </dependency>  
  17.     </dependencies>  

5.重新执行Maven命令mvn -Dmaven.test.Skip -U clean package  成功打成Jar包

如何Spring Boot项目打成JAR包以及WAR包方式

6.我能可以用java -jar web-0.0.1-SNAPSHOT.jar命令启动项目

如何Spring Boot项目打成JAR包以及WAR包方式


二、将Spring Boot 项目打成WAR包

1.跟上面一样执行 Maven命令mvn -Dmaven.test.SKip -U clean package

如何Spring Boot项目打成JAR包以及WAR包方式

会报一个错误 说是必须要增加一个WEB-INF/web.xml文件  遵守Maven插件的规范

如何Spring Boot项目打成JAR包以及WAR包方式

2.在执行Maven命令mvn -Dmaven.test.SKip -U clean package

如何Spring Boot项目打成JAR包以及WAR包方式

完成打成WAR包

如何Spring Boot项目打成JAR包以及WAR包方式

3.直接用java -jar web-0.0.1-SNAPSHOT.war 启动


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2021-09-24
  • 2021-11-18
  • 2021-09-04
猜你喜欢
  • 2021-07-20
  • 2021-06-11
  • 2021-10-27
  • 2021-09-28
  • 2021-11-06
  • 2021-10-10
  • 2020-04-01
相关资源
相似解决方案