我想要做的是根据正在使用的 Maven 配置文件以某种方式替换属性文件中 resources.location 的值。这甚至可能吗?
是的。激活资源过滤并在每个配置文件中定义要替换的值。
在您的ApplicationResources.properties
中,声明一个要替换的令牌,如下所示:
resources.location=${your.location}
在您的 POM 中,<filtering>
为适当的标签添加一个标签<resource>
并将其设置为 true,如下所示:
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
</resources>
...
</build>
...
</project>
然后,在每个配置文件<your.location>
内的元素内添加一个元素:<properties>
<project>
...
<profiles>
<profile>
<id>my-profile</id>
...
<properties>
<your.location>/home/username/resources</your.location>
</properties>
...
</profile>
...
</profiles>
</project>
更多关于资源过滤的信息在这里和这里。