title: How can I set a environment variables in Maven per run?
body: <p>In my project, we've created a Maven module to get the specific JBoss AS and unpacked. <br>
  Then all the test cases can be run under this Jboss AS as embedded container.<br>
  We're using jboss-ejb3-embedded-standalone to call the embedded container, however, it just find the JBOSS_HOME from environment variables and use that one to run.
  Thus we have to update the JBOSS_HOME per mvn install.</p>
  
  <p>I tried to do this in maven by introduce exec-maven-plugin as below:</p>
  
  <pre><code>    &lt;plugin&gt;
      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.2.1&lt;/version&gt;
      &lt;configuration&gt;
          &lt;executable&gt;env&lt;/executable&gt;
          &lt;environmentVariables&gt;
              &lt;JBOSS_HOME&gt;
                  C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}
              &lt;/JBOSS_HOME&gt;
          &lt;/environmentVariables&gt;
      &lt;/configuration&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;resetJbossHome&lt;/id&gt;
              &lt;phase&gt;integration-test&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;exec&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>In the output of console, I can see</p>
  
  <pre><code>[INFO] --- exec-maven-plugin:1.2.1:exec (resetJbossHome) @ test-embedded ---
  ....
  JBOSS_HOME=C:/Sample/embedded-container/jboss-6.1.0.Final
  </code></pre>
  
  <p>....</p>
  
  <p>But when launching JBOSS, it's still running the one with origin JBOSS_HOME set.</p>
  
  <p>Besides, I've tried using maven-antrun-plugin too.</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;copyRelease&lt;/id&gt;
              &lt;phase&gt;pre-integration-test&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;tasks&gt;
                      &lt;exec executable="env"&gt;
         &lt;env key="JBOSS_HOME" value="C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}"/&gt;
      &lt;/exec&gt;
                  &lt;/tasks&gt;
              &lt;/configuration&gt;
              &lt;goals&gt;
                  &lt;goal&gt;run&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>It turns out the same.</p>
  
  <p>Am I wrong on the configuration or there're some better way?</p>