java - 根据maven配置文件排除嵌入式服务器

标签 java spring-boot maven pom.xml embedded-tomcat

我在 pom.xml 中定义了两个不同的配置文件(dev 和 prod)。我不想在使用产品配置文件构建项目时包含嵌入式服务器。我知道即使我不从 jar 中排除嵌入式服务器,我也可以将其部署在其他服务器上。

我已经检查了如何使用下面的代码片段排除 tomcat:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

我无法弄清楚如何根据所选配置文件排除它。以下是我的 POM.xml 的构建和配置文件属性。请指导。

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.properties</include>
                    <include>application-${profileName}.properties</include>
                    <include>*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
</build>
<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profileName>dev</profileName>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profileName>prod</profileName>
            </properties>
        </profile>
</profiles>

提前致谢。

最佳答案

尝试在您的配置文件中使用依赖项标签,仅包含您想要该配置文件的依赖项。

<profiles>
    <profile>
        <id>dev</id>
        <dependencies>
            // do stuff
        </dependencies>
    </profile>
</profiles>

关于java - 根据maven配置文件排除嵌入式服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59510378/

相关文章:

java - Tomcat 不解析 .war 符号链接(symbolic link)

java - Lucene - 第一次应用程序错误

java - 如何使用相同的标签名称解码 java 中的嵌套子元素?

spring-boot - 如何在 Spring Integration 的 react 流中使用事务?

maven - 缺少神器 soapui :SoapUI:jar:5. 2.1

Java Swing : labels and fields apper only after resizing

java - 从多个集合中删除一个对象

javascript - Spring Boot 缩小 javascript

java - Maven 编译失败但未发现错误

java - 如何在 Cloud9 中运行 Maven 构建