简体   繁体   English

在 maven 构建过程中,我应该如何配置 eclipse 以针对不同的 maven 阶段使用不同的环境变量值?

[英]How should I configure the eclipse to make use of different values of environment variable for different maven phases, during maven building process?

Prehistory史前史

Our project builds with maven.我们的项目使用 maven 构建。 We use eclipse.我们使用 eclipse。
In project i have two DB property file:在项目中我有两个数据库属性文件:

  • jdbc.test.properties jdbc.test.properties
  • jdbc.prod.properties jdbc.prod.properties

with the same structure:具有相同的结构:

jdbc.driverClassName=
jdbc.url=
jdbc.username=
jdbc.password=

value of username and password in files are different.文件中用户名和密码的值不同。 So we use different schemes for testes and production.所以我们对睾丸和生产使用不同的方案。

In data-access-config.xml i have the following line:在 data-access-config.xml 我有以下行:

<context:property-placeholder location="classpath:jdbc.${db.flag}.properties"/>

What i do:我所做的:

  1. i click "maven install" (in context menu in eclipse)我单击“maven install”(在 Eclipse 的上下文菜单中)
  2. maven building process runs maven 构建过程运行

What i want:我想要的是:

  • the environment variable "db.flag" was set to "test" during test phase在测试阶段环境变量“db.flag”被设置为“test”
  • the environment variable "db.flag" was set to "prod" during other phases环境变量“db.flag”在其他阶段设置为“prod”

Now i use bat file:现在我使用bat文件:

call mvn test -Ddb.flag=test
call mvn install -Ddb.flag=prod -Dmaven.test.skip=true

But it is not an issue for my team.但这对我的团队来说不是问题。


How should I configure the eclipse to make use of different values of environment variable for different maven phases, during maven building process?在 maven 构建过程中,我应该如何配置 eclipse 以针对不同的 maven 阶段使用不同的环境变量值?

I'll be glad to any advice.我很乐意接受任何建议。

I suggest keeping each copy under the same name (jdbc.properties) in src/main/resources and src/test/resources likewise, so the test phase can pick up your 'test' settings automatically and your location attribute is no longer needed.我建议在 src/main/resources 和 src/test/resources 中将每个副本保持在相同的名称(jdbc.properties)下,这样测试阶段可以自动获取您的“测试”设置,并且不再需要您的位置属性。

Maven will make sure that the test resources are only used at the test phase. Maven 将确保测试资源仅在测试阶段使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM