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

相关推荐
架构师沉默1 天前
别又牛逼了!AI 写 Java 代码真的行吗?
java·后端·架构
后端AI实验室1 天前
我把一个生产Bug的排查过程,交给AI处理——20分钟后我关掉了它
java·ai
凉年技术1 天前
Java 实现企业微信扫码登录
java·企业微信
狂奔小菜鸡1 天前
Day41 | Java中的锁分类
java·后端·java ee
hooknum1 天前
学习记录:基于JWT简单实现登录认证功能-demo
java
程序员Terry1 天前
同事被深拷贝坑了3小时,我教他原型模式的正确打开方式
java·设计模式
NE_STOP1 天前
MyBatis-缓存与注解式开发
java
码路飞1 天前
不装 OpenClaw,我用 30 行 Python 搞了个 QQ AI 机器人
java
Re_zero1 天前
以为用了 try-with-resources 就稳了?这三个底层漏洞让TCP双向通讯直接卡死
java·后端
SimonKing1 天前
Fiddler抓包完全指南:从安装配置到抓包,一文讲透
java·后端·程序员