title: Maven, Jenkins - how to build project to different test environments?
body: <p>I have a Java project containing junit tests that needs to be run on different test environments (Dev, Staging, etc.) via Jenkins. </p>
  
  <p>How can I setup the building of the project to the different environments and how to pass the  url, username and the password to maven? </p>
  
  <p>Can I use maven 3 profiles to read the environment url, username and password from a property file?</p>
  
  <p>Edit: I've added the profiles to the Project POM:</p>
  
  <pre><code>&lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;Integration&lt;/id&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;Staging&lt;/id&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;PP1&lt;/id&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;PP2&lt;/id&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;PP3&lt;/id&gt;
          &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>
  
  <p>How to pass the url, username and the password to these profiles?</p>
  
  <p>Currently the tests are acquiring the test environment details from a property file:</p>
  
  <pre><code> public  class BoGeneralTest extends TestCase {
  
      protected WebDriver driver;
      protected BoHomePage boHomePage;
      protected static Properties systemProps;
      String url = systemProps.getProperty("Url");
      String username = systemProps.getProperty("Username");
      String password = systemProps.getProperty("Password");
      int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
  
      static {
          systemProps = new Properties();
          try {
              systemProps.load(new FileReader(new File("src/test/resources/environment.properties")));
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>The change implemented in the test runner class:</p>
  
  <pre><code>public class BoGeneralTest extends TestCase {
  
      protected WebDriver driver;
      protected BoHomePage boHomePage;
      protected static Properties systemProps;
      String url = systemProps.getProperty("Url");
      String username = systemProps.getProperty("Username");
      String password = systemProps.getProperty("Password");
      int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
      String regUsername = RandomStringUtils.randomAlphabetic(5);
  
      final static String appConfigPath = System.getProperty("appConfig");
  
      static {
          systemProps = new Properties();
          try {
  
              systemProps.load(new FileReader(new File(appConfigPath)));
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>