简体   繁体   中英

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. We use eclipse.
In project i have two DB property file:

  • jdbc.test.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:

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

What i do:

  1. i click "maven install" (in context menu in eclipse)
  2. maven building process runs

What i want:

  • the environment variable "db.flag" was set to "test" during test phase
  • the environment variable "db.flag" was set to "prod" during other phases

Now i use bat file:

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?

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.

Maven will make sure that the test resources are only used at the test phase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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