gpt4 book ai didi

java - maven 中的配置文件 - 选择要构建的文件取决于 maven 中的配置文件

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:17 24 4
gpt4 key购买 nike

我有 application.properties 文件。我希望能够根据 Maven 中所选的配置文件使用另一个 application.properties 文件。你能告诉我如何做到这一点吗?

以上是我对这个问题的想法。也许你知道更好的事情?我的意思是选择jdbc连接的问题。这意味着根据配置文件,我希望能够选择不同的 jdbc url。

最佳答案

类似于:

<profiles>
<profile>
<id>dev</id>
<activation>
<!-- This profile will be default in your IDE -->
<activeByDefault>true</activeByDefault>
</activation>

<build>
<resources>
<resource>
<directory>src/main/resources-dev</directory>
</resource>
</resources>
</build>
</profile>

<profile>
<id>prod</id>

<build>
<resources>
<resource>
<directory>src/main/resources-prod</directory>
</resource>
</resources>
</build>
</profile>
</profiles>

您需要创建两个目录:src/main/resources-devsrc/main/resources-prod。然后给每个目录放一个对应的application.properties:

src
main
java
...
resources-dev
application.properties
resources-prod
application.properties

使用 dev 配置文件进行构建的命令:mvn clean install

命令 使用 prod 配置文件构建:mvn clean install -Pprod

关于java - maven 中的配置文件 - 选择要构建的文件取决于 maven 中的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42744836/

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