通过Maven profile实现既支持war包方式也支持fat jar方式

通过Maven profile实现既支持war包方式也支持fat jar方式

您可以通过使用 Maven 的 profiles 来实现既支持 WAR 打包方式,也支持可执行的 JAR 文件(fat JAR)方式。您可以在不同的 profile 中配置不同的 <packaging>spring-boot-maven-plugin<configuration>

以下是一个示例,演示如何通过 Maven profiles 实现这一目的:

xml 复制代码
<profiles>
    <profile>
        <id>war-packaging</id>
        <activation>
            <activeByDefault>true</activeByDefault> <!-- 设置默认激活该 profile -->
        </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.3</version>
                    <configuration>
                        <executable>true</executable>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

然后,您可以在 <packaging> 中使用 ${packaging.type} 来引用这些 profile 中定义的属性。例如:

xml 复制代码
<packaging>${packaging.type}</packaging>

通过这种方式,您可以根据需要选择不同的 profile 来构建 WAR 包或者可执行的 JAR 文件。

相关推荐
sinat_255487811 天前
transient 修饰符·学习笔记
java·开发语言·spring
jwn9991 天前
SQL Server2019下载及安装教程
java
虚拟世界AI1 天前
Java服务器开发:零基础实战指南
java·servlet·tomcat
码界奇点1 天前
基于模块化架构的Unity游戏开发框架设计与实现
java·c++·unity·架构·毕业设计·源代码管理
后端AI实验室1 天前
同一个需求,我先出技术方案,再让AI出方案——差距让我沉默了
java·ai
xyyaihxl1 天前
springboot与springcloud对应版本
java·spring boot·spring cloud
爱滑雪的码农1 天前
Java基础五:运算符与循环结构
java·开发语言
MrSYJ1 天前
Netty异常传播机制
java·服务器·netty
于先生吖1 天前
基于 Java 开发智慧社区系统:跑腿 + 家政 + 本地生活服务实战教程
java·开发语言·生活
魑魅魍魉都是鬼1 天前
JAVA面向对象设计的五大原则
java