我想在 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 的文件:
之后,我运行以下命令:
“mvn clean install -DskipTests -Pdev”或
“mvn clean install -DskipTests -Denvironment=dev”
我一直将我的 token 放在属性文件中,它永远不会被替换...
如果有人可以帮助我,提前致谢!
请您参考如下方法:
如果您有一个带有过滤器属性的文件,您应该
- 在
<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