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

相关推荐
进阶的猿猴10 分钟前
easyExcel实现单元格合并
java·excel
小许学java24 分钟前
MySQL-触发器
java·数据库·mysql·存储过程·触发器
JEECG低代码平台27 分钟前
【2025/11】GitHub本月热度排名前十的开源Java项目
java·开源·github
百***860531 分钟前
Spring BOOT 启动参数
java·spring boot·后端
跟着珅聪学java38 分钟前
Spring Boot 中整合 MySQL 并打印 SQL 日志
java·spring boot
ᐇ95941 分钟前
Java集合框架实战:HashMap与HashSet的妙用
java·开发语言
阿智智41 分钟前
用Maven的quickstart archetype创建项目并结合JUnit5单元测试
java·单元测试·maven·junit5
乂爻yiyao1 小时前
设计模式思想——从单例模式说起
java·单例模式·设计模式
q***11651 小时前
SpringBoot创建动态定时任务的几种方式
java·spring boot·spring
by__csdn1 小时前
微服务与单体那些事儿
java·后端·微服务·云原生·架构