gpt4 book ai didi

maven-2 - Maven 根据配置文件更改文件中的值

转载 作者:行者123 更新时间:2023-12-02 05:35:35 24 4
gpt4 key购买 nike

我的应用程序中有一个名为 ApplicationResources.properties 的属性文件,其中的属性会根据环境而变化。假设该属性是:

     resources.location=/home/username/resources

当应用程序在开发期间执行时和应用程序投入生产时,该值是不同的。

我知道我可以在 Maven 中使用不同的配置文件在不同的环境中执行不同的构建任务。我想要做的是根据正在使用的 Maven 配置文件以某种方式替换属性文件中 resources.location 的值。这可能吗?

最佳答案

What I want to do is somehow replace the value of the resources.location in the properties file based on the Maven profile in use. Is this even possible?

是的。激活资源过滤并定义每个配置文件中要替换的值。

在您的 ApplicationResources.properties 中,声明一个要替换的 token ,如下所示:

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>

有关资源过滤的更多信息 herehere .

关于maven-2 - Maven 根据配置文件更改文件中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2335431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com