我想提一下我在 Maven 配置方面相对较新。
我的情况:
- 我使用 Maven 3.0.5 构建 J2E 应用程序
- 该应用程序部署在四种不同的环境中:本地、开发、测试和生产
- 我使用 maven 配置文件来配置特定于环境的配置
- 我已经
properties
在文件系统的文件中定义了这些配置。
这是那些文件系统:
<my-project-root>
---profiles
------local
---------app.properties
------dev
---------app.properties
------test
---------app.properties
我在我的以下逻辑中加载了相应的属性文件pom.xml
:
<profiles>
<profile>
<id>local</id>
<!-- The development profile is active by default -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<build.profile.id>prod</build.profile.id>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
</properties>
</profile>
</profiles>
<build>
<finalName>MyProject</finalName>
<plugins>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>profiles/${build.profile.id}</directory>
</resource>
</resources>
</build>
使用此配置,我几乎可以在任何地方为我的当前配置文件使用相应的属性。无处不在,但<plugins>
部分。我非常想从这些属性文件中加载例如我的数据库 url 或凭据,但是如果我将它们包含在它们中,app.properties
它们就不会在插件部分中进行评估(例如,我获得了${endpoint}
作为数据库端点的值)。
如何从该<plugins>
部分中可访问的配置文件的文件中获取属性?
PS:是的,如果我直接在标签下的pom.xml
as 属性中添加这些属性<profiles>
,它们是可以访问的,但我宁愿将我的密码保留在 pom.xml 中。