java - Maven 根据配置文件更新属性

标签 java maven maven-2 maven-profiles

我想在 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 的项目,这里是 src/main/resources 下名为 front-config.properties 的文件:

enter image description here

之后,我运行以下命令:

“mvn clean install -DskipTests -Pdev”或

“mvn clean install -DskipTests -Denvironment=dev”

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

如果有人可以帮助我,提前致谢!

最佳答案

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

  1. <profile> 中找到过滤器属性文件的位置

```

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

```

  • <build> 中添加过滤标签
  • ```

    <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

    关于java - Maven 根据配置文件更新属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43869842/

    相关文章:

    java - 如何在 Java 的纸牌游戏中显示纸牌并使其可点击进行选择?

    java - 带排序功能的 JTable 渲染器

    java - 具有 Jersey 2.x 和 RESTEasy 依赖项的项目是否可行?

    java - 跨多个项目划分Spring配置

    maven-2 - 如何在没有共同父项的情况下一步构建多个 Maven 项目?

    java - NullPointerException 从构造函数启动时

    java - 重载中调用原始方法

    maven - 无法解析类org.jenkinsci.plugins.workflow.support.steps.build.DownstreamFailureCause

    maven - Maven 如何删除其中包含给定文本字符串的所有文件?

    java - Eclipse 中的 Maven 启动配置