title: Setting a system variable within a maven profile
body: <p>Is it possible within maven to set a system property that is attainable from within a java class.</p>
  
  <p>I have seen that this is possible (<a href="https://stackoverflow.com/questions/9622121/pass-a-java-parameter-from-maven">here</a>) within the surefire plugin as follows;</p>
  
  <pre><code>String param = System.getProperty("my_parameter1");
  
  &lt;configuration&gt;
      &lt;systemPropertyVariables&gt;
          &lt;my_property1&gt;${my_property1}&lt;/my_property1&gt;
      &lt;/systemPropertyVariables&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>However I would like to get a handle on the environment I am working in, I am already passing prod or dev as a maven profile argument - is it possible somehow to get a handle in the code on this either from setting a variable in the profile i call and then calling system.getProperty or some other way?</p>
  
  <p>Thanks</p>
  
  <p><strong>my pom file</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;core&lt;/groupId&gt;
      &lt;artifactId&gt;core&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;build&gt;
          &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
          &lt;testSourceDirectory&gt;test&lt;/testSourceDirectory&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.17&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;parallel&gt;methods&lt;/parallel&gt;
                      &lt;threadCount&gt;10&lt;/threadCount&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;sonar-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.1&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src&lt;/directory&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/*.java&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/resource&gt;
              &lt;resource&gt;
                  &lt;directory&gt;resources&lt;/directory&gt;
                  &lt;includes&gt;
                      &lt;include&gt;**/*.png&lt;/include&gt;
                  &lt;/includes&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
      &lt;/build&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-lang&lt;/groupId&gt;
              &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
              &lt;version&gt;2.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-codec&lt;/groupId&gt;
              &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
              &lt;version&gt;1.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mariadb.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;mariadb-java-client&lt;/artifactId&gt;
              &lt;version&gt;1.1.7&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.11&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mockito&lt;/groupId&gt;
              &lt;artifactId&gt;mockito-all&lt;/artifactId&gt;
              &lt;version&gt;1.9.5&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.facebook4j&lt;/groupId&gt;
              &lt;artifactId&gt;facebook4j-core&lt;/artifactId&gt;
              &lt;version&gt;[2.0,)&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.relayrides&lt;/groupId&gt;
              &lt;artifactId&gt;pushy&lt;/artifactId&gt;
              &lt;version&gt;0.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.16&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.sun.mail&lt;/groupId&gt;
              &lt;artifactId&gt;javax.mail&lt;/artifactId&gt;
              &lt;version&gt;1.5.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;4.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.mail&lt;/groupId&gt;
              &lt;artifactId&gt;javax.mail-api&lt;/artifactId&gt;
              &lt;version&gt;1.5.2&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.activation&lt;/groupId&gt;
              &lt;artifactId&gt;activation&lt;/artifactId&gt;
              &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.threewks.thundr&lt;/groupId&gt;
              &lt;artifactId&gt;thundr-mailgun&lt;/artifactId&gt;
              &lt;version&gt;1.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
              &lt;version&gt;1.3.2&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;2.3&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;DEV&lt;/id&gt;
              &lt;properties&gt;
                  &lt;swifte.url&gt;jdbc:mariadb://ip:3306/swifte?autoReconnect=true&lt;/swifte.url&gt;
                  &lt;swifte.username&gt;user&lt;/swifte.username&gt;
                  &lt;swifte.password&gt;pass&lt;/swifte.password&gt;
              &lt;/properties&gt;
              &lt;build&gt;
                  &lt;resources&gt;
                      &lt;resource&gt;
                          &lt;directory&gt;resources&lt;/directory&gt;
                          &lt;includes&gt;
                              &lt;include&gt;JavaPNSDev.p12&lt;/include&gt;
                          &lt;/includes&gt;
                      &lt;/resource&gt;
                  &lt;/resources&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;PROD&lt;/id&gt;
              &lt;properties&gt;
                  &lt;swifte.url&gt;jdbc:mariadb://ip:3306/swifte?autoReconnect=true&lt;/swifte.url&gt;
                  &lt;swifte.username&gt;username&lt;/swifte.username&gt;
                  &lt;swifte.password&gt;pass&lt;/swifte.password&gt;
              &lt;/properties&gt;
              &lt;build&gt;
                  &lt;resources&gt;
                      &lt;resource&gt;
                          &lt;directory&gt;resources&lt;/directory&gt;
                          &lt;includes&gt;
                              &lt;include&gt;JavaPNSProd.p12&lt;/include&gt;
                          &lt;/includes&gt;
                      &lt;/resource&gt;
                  &lt;/resources&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>