8

In my project, we've created a Maven module to get the specific JBoss AS and unpacked.
Then all the test cases can be run under this Jboss AS as embedded container.
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.

I tried to do this in maven by introduce exec-maven-plugin as below:

    <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>

In the output of console, I can see

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

....

But when launching JBOSS, it's still running the one with origin JBOSS_HOME set.

Besides, I've tried using maven-antrun-plugin too.

<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>

It turns out the same.

Am I wrong on the configuration or there're some better way?

4

1 回答 1

8

查看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>

在你的 exec 插件中:

<environmentVariables>
    <JBOSS_HOME>
        ${jboss.home}
    </JBOSS_HOME>
</environmentVariables>
于 2012-02-08T09:22:10.293 回答