如何在每次运行的Maven中设置环境变量?

Edi*_*son 7 jboss maven exec-maven-plugin

在我的项目中,我们创建了一个Maven模块来获取特定的JBoss AS并解压缩.
然后,所有测试用例都可以作为嵌入式容器在此Jboss AS下运行.
我们使用jboss-ejb3-embedded-standalone来调用嵌入式容器,但是,它只是从环境变量中找到JBOSS_HOME并使用它来运行.因此,我们必须每mvn安装更新JBOSS_HOME.

我试着在maven中通过引入exec-maven-plugin来做到这一点,如下所示:

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
        <executable>env</executable>
        <environmentVariables>
            <JBOSS_HOME>
                C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}
            </JBOSS_HOME>
        </environmentVariables>
    </configuration>
    <executions>
        <execution>
            <id>resetJbossHome</id>
            <phase>integration-test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

在控制台的输出中,我可以看到

[INFO] --- exec-maven-plugin:1.2.1:exec (resetJbossHome) @ test-embedded ---
....
JBOSS_HOME=C:/Sample/embedded-container/jboss-6.1.0.Final
Run Code Online (Sandbox Code Playgroud)

....

但是在启动JBOSS时,它仍在运行JBOSS_HOME设置源的JBOSS.

此外,我也试过使用maven-antrun-plugin.

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <id>copyRelease</id>
            <phase>pre-integration-test</phase>
            <configuration>
                <tasks>
                    <exec executable="env">
       <env key="JBOSS_HOME" value="C:/Sample/embedded-container/jboss-${version.org.jboss.jbossas}"/>
    </exec>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

事实证明是一样的.

我配置错了还是有更好的方法?

nde*_*rge 7

看看Maven的个人资料.

您可以定义一个用于测试的配置文件,一个用于生产,具有不同属性,例如

<profiles>
  <profile>
    <id>test</id>
    <jboss.home>PATH TO JBOSS TEST INSTANCE</jboss.home>
  </profile>
  <profile>
    <id>prod</id>
    <jboss.home>PATH TO JBOSS PROD INSTANCE</jboss.home>
  </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

在您的exec插件中:

<environmentVariables>
    <JBOSS_HOME>
        ${jboss.home}
    </JBOSS_HOME>
</environmentVariables>
Run Code Online (Sandbox Code Playgroud)