title: Maven Profile for testing
body: <p>I am developing a java web application (No Spring).I wanted to use separate db for production and testing.I have two files in src/main/resources - env.properties and env.test.properties.
  I have defined the profile in pom.xml as mentioned in <a href="https://maven.apache.org/guides/mini/guide-building-for-different-environments.html" rel="noreferrer">https://maven.apache.org/guides/mini/guide-building-for-different-environments.html</a>.</p>
  
  <pre><code> &lt;profiles&gt;
     &lt;profile&gt;
       &lt;id&gt;test&lt;/id&gt;
       &lt;build&gt;
         &lt;plugins&gt;
           &lt;plugin&gt;
             &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
             &lt;executions&gt;
               &lt;execution&gt;
                 &lt;phase&gt;test&lt;/phase&gt;
                 &lt;goals&gt;
                   &lt;goal&gt;run&lt;/goal&gt;
                 &lt;/goals&gt;
                 &lt;configuration&gt;
                   &lt;tasks&gt;
                     &lt;delete file="${project.build.outputDirectory}/environment.properties"/&gt;
                     &lt;copy file="src/main/resources/environment.test.properties"
                           tofile="${project.build.outputDirectory}/environment.properties"/&gt;
                   &lt;/tasks&gt;
                 &lt;/configuration&gt;
               &lt;/execution&gt;
             &lt;/executions&gt;
           &lt;/plugin&gt;
           &lt;plugin&gt;
             &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
             &lt;configuration&gt;
               &lt;skip&gt;true&lt;/skip&gt;
             &lt;/configuration&gt;
           &lt;/plugin&gt;
           &lt;plugin&gt;
             &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
             &lt;executions&gt;
               &lt;execution&gt;
                 &lt;phase&gt;package&lt;/phase&gt;
                 &lt;goals&gt;
                   &lt;goal&gt;jar&lt;/goal&gt;
                 &lt;/goals&gt;
                 &lt;configuration&gt;
                   &lt;classifier&gt;test&lt;/classifier&gt;
                 &lt;/configuration&gt;
               &lt;/execution&gt;
             &lt;/executions&gt;
           &lt;/plugin&gt;
         &lt;/plugins&gt;
       &lt;/build&gt;
     &lt;/profile&gt; 
  </code></pre>
  
  <p>However, when I run test by maven test -Ptest, I see that my test is getting executed with the db from env.properties and then after completion of test , the profile switching happens.
  I am also having a jebkins pipeline which builds tests and deploys.
  Am I missing something here ? What is the correct way to read the properties from env.test.properties(activate the profile and run test) ?</p>
  
  <p>Thanks a lot.</p>