maven - 为 Maven pom 提供外部参数并在 application.properties 文件中替换相同的参数
问题描述
我正在处理 testNg 项目,我需要为 pom.xml 提供外部参数,这些参数应该在 application.properties 文件中替换,该文件将在我的项目中进一步使用。谁能列出我需要使用的步骤和插件。
解决方案
我已经解决了这个问题。我在 pom.xml 中添加了一个配置文件并为属性替换添加了配置。
<profiles>
<profile>
<id>profile1</id>
<properties>
<url>https://www.bing.com</url>
<search>bitcoin</search>
</properties>
</profile>
</profiles>
<build>
<testOutputDirectory>${basedir}/target/classes</testOutputDirectory>
<filters>
<filter>src/main/resources/runtime.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
运行时属性
url=${url}
search=${search}
运行测试:
mvn test -Pprofile1 -Durl=https://www.google.com -Dsearch=Blockchain
url 和 search 变量的值将在 runtime.properties 文件中替换为上述命令的参数中给出的值。
-Durl=https://www.google.com and
-Dsearch=Blockchain
推荐阅读
- azure - 来自二进制 blob 数据的 Azure PolyBase 外部表?
- ionic-framework - ionic 4 添加侧边菜单
- cordova - 如何解决 Cordova 签名问题?
- python - 在 Python 中编写更快的回溯算法
- c# - 如何确定执行环境平台
- php - Laravel 5 - 从集合中获取值并传递给视图
- bash - 带有 for 循环和 ssh 的 Bash 文件
- python - Django Postgres ArrayField 迁移
- c - 剔除适用于从视图投影矩阵中提取平面,但不适用于投影矩阵
- c# - 我可以在 C# 中为子类(反射/发射吗?)在运行时创建(添加)方法覆盖