在maven管理中,我们可以灵活切换jar和war 2种打包方式。在pom.xml引入profiles 标签来实现我们的需求,比如我们本地直接运行jar 开发和测试,线上我需要打包war文件,看看我的配置文件如下:
<profiles>
<profile>
<id>war-packaging</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<packaging.type>war</packaging.type>
</properties>
</profile>
<profile>
<id>fat-jar-packaging</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.15</version>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
在打包标签中配置该变量,都是在project 标签下:
<packaging>${packaging.type}</packaging>
刷新后,点击idea 右侧栏maven按钮,

您需要那种打包方式您就激活那种即可。
clean->compile->package,完成打包。
