0

How can use two Maven profiles with for example <id = env>that will contain id, password, account# that will pass those values into .java class and in Maven command line I just run something like:

mvn test ${env=stage}

and it will take id, password, account# from profile that I choose. Or may be there are other way to do that not using profiles?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
Ilya G
  • 447
  • 2
  • 7
  • 17

1 Answers1

0

In general, you can declare properties in Maven. You can set them in different ways:

  • Command line:

    mvn ... -DmyProperty=myValue
    
  • In a <properties> section in a POM or in settings.xml (in the latter in a <profile> section only) like:

    <profile>
      <id>stage</id>
    
      <properties>
        <user>you</user>
        <password>your</password>
        <accountNo>42</accountNo> 
      </properties>
    <profile>
    

Activate profiles on the command line with:

mvn ... -Pstage ...

or use one of the other activation mechanisms described in the doc Maven, Introduction to Build Profiles.

Use properties in your POM with ${user}, ${password}, ${accountNo}.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • `Use properties in your POM with ${user}, ${password}, ${accountNo}.` How can I use those values in my .java class after that. Should be something like that : `String id = ${user} ` or this id I should put in properties file and then in java class call for it? – Ilya G Jun 04 '16 at 22:38
  • @IlyaG It depends on whether you want/need it hardcoded in your class or in an external properties file. The latter is the usual. There is a mechanism in Maven called [_Resource Filtering_](https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) (A bad name, IMHO, because with a filter you sort something out. _Resource Interpolation_ would be more appropriate.) See also [Filtering source code in Maven](http://stackoverflow.com/questions/4106171/filtering-source-code-in-maven). – Gerold Broser Jun 05 '16 at 12:11