【发布时间】:2017-12-23 19:26:04
【问题描述】:
我正在尝试设置一个 Maven pom.xml 文件,以便它会
- 构建我的战争文件
- 使用具有数据库资源的 context.xml 启动 tomcat
- 通过 settings.xml 或属性文件在 context.xml 中设置用户名和密码
我需要用户名和密码在项目外部,这样敏感信息就不会存储在版本控制中。
如果我硬编码用户名和密码,Maven tomcat 插件工作正常。我将 context.xml 文件放入 src/test/resources/tomcat/context.xml 并配置插件以从那里提取它:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<contextFile>
${project.basedir}/src/test/resources/tomcat/context.xml
</contextFile>
</configuration>
</plugin>
我见过将用户名和密码放在 .m2/settings.xml 文件中的示例,如下所示:
<servers>
<server>
<id>demo</id>
<username>myUser</username>
<password>myPassword</password>
</server>
<servers>
但我不知道如何将这些值“注入”到 context.xml 中。我在 context.xml 中的适当位置添加了以下内容:
${servers.server.demo.username}
或
${servers.server.username}
但它们并没有解决实际值。
这种事情的最佳做法是什么?
【问题讨论】:
标签: maven tomcat tomcat7 maven-tomcat-plugin