【问题标题】:Maven filtering resourcesMaven过滤资源
【发布时间】:2016-08-16 07:04:52
【问题描述】:

我正在运行一个简单的 maven 项目(maven 版本 3.3.9),其中包含配置文件和资源过滤。似乎过滤总是在默认配置文件上完成。

在 src/main/filters 中有 2 个配置文件(默认):config-dev.properties 和 config-prod.properties 只包含一个变量 application.env=开发 应用程序.env=生产

以及 src/main/resources 中的资源文件(默认)包含以下内容:

We are working on ${application.env}

使用的命令行是 mvn clean resources:resources -Pprod

预期的输出是

We are working on production

但过滤后的资源文件包含

We are working on development

Maven pom sn-p 看起来像:

<build>
    <finalName>test-maven-module</finalName>
    <filters>
        <filter>src/main/filters/config-${build.profile.id}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

和配置文件配置

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.profile.id>dev</build.profile.id>
        </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <build.profile.id>prod</build.profile.id>
            </properties>
    </profile>
</profiles>

有什么建议吗?

【问题讨论】:

    标签: maven filtering profile


    【解决方案1】:

    我在帖子Eclipse + maven : profile ignored找到了解决方案

    问题在于使用“使用本机挂钩或轮询刷新”选项(首选项 > 常规 > 工作区 > 使用本机挂钩刷新)。取消选中此选项可解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-11
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多