【问题标题】:Maven update property based on profileMaven 根据配置文件更新属性
【发布时间】:2017-05-09 12:26:51
【问题描述】:

我想在 Maven 构建期间更改不同属性的值。 Maven Change a value in a file based on profile 我也尝试了很多其他方法,但它从来没有用过,我不明白为什么......

这是我的 pom.xml

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <property>
                <name>environment</name>
                <value>dev</value>
            </property>
        </activation>
        <properties>
            <aem.url.prop>hugoL</aem.url.prop>
        </properties>
    </profile>
</profiles>
<build>
<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>
<plugins>
  <plugin>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <executable>true</executable>
        </configuration>
    </plugin>
</plugins>

我有一个基于 maven 的项目,这里有一个名为 front-config.properties 的文件中的 src/main/resources 下的内容:

之后,我运行以下命令:

“mvn clean install -DskipTests -Pdev”或

“mvn clean install -DskipTests -Denvironment=dev”

我的令牌一直在属性文件中,它永远不会被替换...

如果有人可以帮助我,在此先感谢!

【问题讨论】:

  • 你能显示属性文件吗?
  • 我添加了一个带有属性文件及其包含内容的屏幕截图
  • @Jens 我按你的要求添加了截图

标签: java maven maven-2 maven-profiles


【解决方案1】:

如果你有一个带有过滤属性的文件,你应该

  1. 在您的&lt;profile&gt; 中有过滤器属性文件的位置

```

<properties>
    <filter.properties>filter-values-myId.properties</filter.properties>
</properties>

```

  1. &lt;build&gt; 中添加过滤器标签

```

<filters>
    <filter>${[a filter property] file location}</filter>
</filters>

```

参考:https://gist.github.com/Qkyrie/6018561

https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

【讨论】:

  • 我不明白我需要做什么,在我放的链接中,这家伙没有解释这一点,情况就像我一样......
猜你喜欢
  • 1970-01-01
  • 2010-12-03
  • 2013-09-24
  • 2020-06-03
  • 2018-07-15
  • 2023-04-08
  • 2017-10-06
  • 2011-01-21
  • 1970-01-01
相关资源
最近更新 更多