如何使用 maven 或 pom.xml 更新属性文件 [英] how to update a property file using maven or pom.xml

查看:65
本文介绍了如何使用 maven 或 pom.xml 更新属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自动化框架,我正在从一个属性文件中读取值,比如config.properties".

I have created an automation framework where I am reading values from a property file say "config.properties".

我的 config.properioes 文件包含以下内容:

My config.propertioes file contains following :

BrowserName=${browser}
Environment=${env}

我正在从属性文件中读取浏览器值并将其传递给我的 selenium 脚本以运行它.

I am reading browser value from the property file and passing it to my selenium script to run it.

现在我想替换 "${browser}" &&"${env}" 值为 "ie" &&IT" 使用 pom.xml.有什么方法/插件可以使用 pom.xml 编辑属性文件.

Now I wants to replace "${browser}" && "${env}" with value "ie" && "IT" using pom.xml. Is there any way/plugin using which I can edit a property file using pom.xml.

请提出建议.

@Keshava我将整个示例放在下面,如下所示:1.有2个属性文件: ◦project.properties:这是我们在存储库中提交的文件.它包含如下数据:◾project.connection.username=@@DB_USERNAME@@project.connection.password=@@DB_PASSWORD@@

@Keshava I am putting whole example below as suggested below : 1.Have 2 property files: ◦project.properties: This is the file that we commit in the repository. It consists data as follows: ◾project.connection.username=@@DB_USERNAME@@ project.connection.password=@@DB_PASSWORD@@

◦build.properties:这是我们不会在存储库中提交并在每个部署环境中维护的文件,无论是开发人员环境、UAT 环境还是生产环境.该文件的内容如下: ◾db.username=mydbuserdb.password=mydbpassword

◦build.properties: This is the file that we do not commit in the repository and is maintained at each of the deployment environments, be it the developers env., UAT env or Production env. The contents of this file are as follows: ◾db.username=mydbuser db.password=mydbpassword

2.在项目的pom.xml中添加如下插件和执行:

2.In the project’s pom.xml add the following plugin and a execution:

<plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>maven-replacer-plugin</artifactId>
                <version>1.3.5</version>
                <executions>
                    <execution>
                        <id>replaceTokens</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <file>target/classes/project.properties</file>
                    <replacements>
                        <replacement>
                            <token>@@DB_USERNAME@@</token>
                            <value>${db.username}</value>
                        </replacement>
                        <replacement>
                            <token>@@DB_PASSWORD@@</token>
                            <value>${db.password}</value>
                        </replacement>
                    </replacements>
                </configuration>
</plugin>

从上面,我了解到 "@@DB_USERNAME@@" 来自 "project.properties".但是,这个 "${db.username}" 值将从哪个属性文件中获取?.我的 pom 如何理解从哪里取 "${db.username}" .

from above, I understand that "@@DB_USERNAME@@" is from "project.properties". But, from which properties file this "${db.username}" value will be taken?. how my pom will understand from where to take "${db.username}" .

我是否需要像下面这样在 Maven 目标中传递这个值:

Do I need to pass this value in maven goal like below :

mvn clean install -Ddb.username=myuserid

推荐答案

您可以尝试使用 maven 替换插件请参阅 https://code.google.com/archive/p/maven-替换插件/

you could tryin using the maven replacer plugin See https://code.google.com/archive/p/maven-replacer-plugin/

查看示例 这里

这篇关于如何使用 maven 或 pom.xml 更新属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆