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?

aldoWan
  • 93
  • 1
  • 6
Edison
  • 101
  • 1
  • 1
  • 2

1 Answers1

9

Take a look at the Maven profiles.

You can define one profile for testing, one for production, with different properties, such as

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

And in your exec plugin :

<environmentVariables>
    <JBOSS_HOME>
        ${jboss.home}
    </JBOSS_HOME>
</environmentVariables>
ndeverge
  • 21,378
  • 4
  • 56
  • 85
  • Actually, the real problem is after setting the environmentVariables, it won't effect when launching JBoss AS, no matter whatever you set. :( – Edison Feb 08 '12 at 09:40
  • Is JBoss lauched in a separated process ? Maybe this process inherits from the base env, and not the env from your launching process ? – ndeverge Feb 08 '12 at 09:48
  • In my project, the JUnit test is launched by maven-failsafe-plugin, and in the test case itself will invoke createEJBContainer method implemented by jboss-ejb3-embedded-standalone jar, who will launch the jboss as container. – Edison Feb 09 '12 at 02:00
  • Env setup is in Maven, I'm not sure whether this setup will effect the JVM launched by it or not... If the configuration is correct, we can say not, so first point is to verify the correct of the config above... – Edison Feb 09 '12 at 03:14
  • Just to make sure that I understand : you need to launch a different JBoss EJB container version for test, and one other for prod. If so, why don't you use different dependencies instead of using environment variables ? – ndeverge Feb 09 '12 at 08:01
  • jboss-ejb3-embedded-standalone only loads the JBOSS_HOME from env variable to launch JBoss. That's why I have to change the JBOSS_HOME instead of using different dependencies. – Edison Feb 10 '12 at 04:52