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

相关推荐
隔窗听雨眠6 分钟前
ORM框架选型指南:MyBatis与Hibernate的全面对比
java·开发语言·数据库
j7~14 分钟前
【C++】类和对象(上)--带你全面理解类和对象的概念,以及this指针的理解和相关面试题
java·开发语言·封装·this指针·类的实例化·访问限定符·类的命名
于先生吖15 分钟前
同城物流创业项目,Java源码搭建多车型搬家拉货、就近配货预约小程序
java·开发语言·小程序
码不停蹄的玄黓16 分钟前
Java 异常分类
java·开发语言
江湖中的阿龙21 分钟前
23种设计模式
java·开发语言·设计模式
可可嘻嘻大老虎22 分钟前
SpringBoot拦截器防重复提交实战
java·spring boot·后端
RainCityLucky27 分钟前
Java Swing 自定义组件库分享(十一)
java·笔记·后端
ch.ju27 分钟前
Java Programming Chapter 4——The set method assigns a value to the property.
java·开发语言
Sam_Deep_Thinking28 分钟前
SaaS多租户业务差异化:扩展点机制的设计与实现
java·架构
我登哥MVP32 分钟前
Spring Boot 从“会用”到“精通”:Rest风格原理
java·spring boot·后端·spring·maven·intellij-idea·mybatis