通过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 文件。

相关推荐
伯牙碎琴4 分钟前
八、TOGAF(架构治理Architecture Governance)
java·微服务·架构
liuyang-neu10 分钟前
力扣 16.最接近的三数之和
java·数据结构·算法·leetcode
艾伦~耶格尔11 分钟前
Java API 之集合框架进阶
java·开发语言·学习
韩子谦12 分钟前
Java迭代器Iterator和Iterable有什么区别?
java·windows·python
Satan71214 分钟前
【Java】全面理解Java8特性
java·开发语言
至简行远16 分钟前
路由器接口配置DHCP实验简述
java·服务器·网络·数据结构·python·算法·智能路由器
c1tenj217 分钟前
SpringCloud Feign 以及 一个标准的微服务的制作
java·spring cloud·微服务
小郝同学(恩师白云)31 分钟前
SpringMVC后续4
java·服务器·前端
March€35 分钟前
基于mockito做单元测试
java·单元测试·log4j
秋月的私语42 分钟前
c# 线程等待变量的值符合条件
java·jvm·c#