一、将Spring Boot项目打成JAR包
1.先选择项目的根目录 IDEA
2.在命令窗口cmd中cd 项目路径→选中路径的磁盘
3.输入Maven命令 mvn -Dmaven.test.Skip -U clean package
4.如果是Maven多层架构 会报错 找不到启动类
将启动类配置到web里的pom.xml中
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>fristappdemo.FristAppDemoApplicationTests</mainClass>
</configuration>
</plugin>
</plugins>
</build>
各层相互依赖 web→service→model
<!--web里pom.xml-->
<dependencies>
<dependency>
<groupId>com.xcy</groupId>
<artifactId>persistence</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<!--service里pom.xml-->
<dependencies>
<dependency>
<groupId>com.xcy</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
web→service→model
<!--web里pom.xml-->
<dependencies>
<dependency>
<groupId>com.xcy</groupId>
<artifactId>persistence</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<!--service里pom.xml-->
<dependencies>
<dependency>
<groupId>com.xcy</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
5.重新执行Maven命令mvn -Dmaven.test.Skip -U clean package 成功打成Jar包
6.我能可以用java -jar web-0.0.1-SNAPSHOT.jar命令启动项目
二、将Spring Boot 项目打成WAR包
1.跟上面一样执行 Maven命令mvn -Dmaven.test.SKip -U clean package
会报一个错误 说是必须要增加一个WEB-INF/web.xml文件 遵守Maven插件的规范
2.在执行Maven命令mvn -Dmaven.test.SKip -U clean package
完成打成WAR包
3.直接用java -jar web-0.0.1-SNAPSHOT.war 启动
以上就是两种打包方式。 end........