4 Replies Latest reply on Nov 20, 2007 4:01 PM by jgilbert

    EAR vs WAR Deployment

    jgilbert

      I've been watching JSFUnit for a while and I just started experimenting with it today. I am a fan so far!

      However, I deploy my application in an Ear and all the examples I have seen so far deploy as a War.

      I have tried a few different ways so far and they all feel sloppy. I am using maven. So far I have created an alternate war project to cactify my war. I have put my jsfunit classes in my ear project. The ear project has a 'test' profile that depends on the alternate war and deploys the ear and runs the tests. This feels sloppy because all the test logic and configuration is spread across multi projects.

      I'm thinking of trying to create an totally independent project that uses cactifyEar and then deploys and runs the tests.

      Does anyone have any thoughts on the best way to go about deploying as an Ear?

        • 1. Re: EAR vs WAR Deployment
          ssilvert

          I was talking with some of the Maven developers about this at ApacheCon last week. I got some ideas but I haven't had time to try them out yet.

          From what I learned, I think that first it would be best to use submodules instead of separate projects. This would keep things a little closer together but still modularized.

          The Maven guys said that when creating an EAR you should indeed build all of your WARs in separate submodules and just use the EAR module to bring all the pieces together.

          So all together, I would have three Maven submodules.
          1) EAR submodule
          2) WAR submodule
          3) JSFUnit submodule that depends on module #2

          I would put my JSFUnit tests in module #3. Module #1 would depend on module #3 if in test mode. Otherwise it depends on module #2.

          Hope that helps,

          Stan
          http://www.jsfunit.org

          • 2. Re: EAR vs WAR Deployment
            jgilbert

            That is what I have so far. But putting the tests in module #3 doesn't allow me to run the tests, because I need to run the tests as part of the Ear build.

            I'm not sure if I can trigger the tests that are in #3 because it is packaged as a war instead of a jar.

            I'm sure we can figure something out!

            • 3. Re: EAR vs WAR Deployment
              ssilvert

               

              "jgilbert" wrote:

              I'm sure we can figure something out!


              OK. I see your problem now. Surely Cactus users have run into this as well, so there must be a solution.

              Have you tried using inclusions that point back to the source in module #3?

              http://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html

              Stan

              • 4. Re: EAR vs WAR Deployment
                jgilbert

                OK, its not perfect, but this is working well.

                I have added a QA submodule that is built last by the master module.
                It is a war that depends on the primary war and overlays it.
                It also contains the jsfunit tests.
                I then use antrun to grab the previously built ear and overlay it with the new qa version of the war.
                Then I use cargo to deploy the ear.
                Then surefire runs the tests.

                This is the maven command:

                mvn clean install -P test


                So far so good. I'm going to run with this until I come across something better.


                <?xml version="1.0" encoding="UTF-8"?>
                <project>
                 <modelVersion>4.0.0</modelVersion>
                 <groupId>catalog</groupId>
                 <artifactId>catalog-qa</artifactId>
                 <version>1.1.0</version>
                 <packaging>war</packaging>
                 <dependencies>
                 <dependency>
                 <groupId>catalog</groupId>
                 <artifactId>catalog-web</artifactId>
                 <version>${pom.version}</version>
                 <type>war</type>
                 <scope>runtime</scope>
                 </dependency>
                 <dependency>
                 <groupId>org.jboss</groupId>
                 <artifactId>jboss-jsfunit-core</artifactId>
                 <version>1.0-SNAPSHOT</version>
                 <scope>compile</scope>
                 </dependency>
                 </dependencies>
                 <build>
                 <sourceDirectory>src/test/java</sourceDirectory>
                 <testSourceDirectory>src/test/java</testSourceDirectory>
                 <plugins>
                 <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-war-plugin</artifactId>
                 <configuration>
                 <dependentWarExcludes>WEB-INF/web.xml</dependentWarExcludes>
                 </configuration>
                 </plugin>
                 <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
                 <skip>true</skip>
                 </configuration>
                 </plugin>
                 </plugins>
                 </build>
                 <profiles>
                 <profile>
                 <id>test</id>
                 <build>
                 <plugins>
                 <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-antrun-plugin</artifactId>
                 <executions>
                 <execution>
                 <phase>pre-integration-test</phase>
                 <configuration>
                 <tasks>
                 <property name="ear.name" value="${groupId}-app-${version}.ear"/>
                 <unzip
                 src="${settings.localRepository}/${groupId}/${groupId}-app/${version}/${ear.name}"
                 dest="${basedir}/target/${ear.name}"/>
                
                 <copy
                 todir="${basedir}/target/${ear.name}/${groupId}-web-${version}.war">
                 <fileset dir="${basedir}/target/${artifactId}-${version}"/>
                 </copy>
                 </tasks>
                 </configuration>
                 <goals>
                 <goal>run</goal>
                 </goals>
                 </execution>
                 </executions>
                 </plugin>
                 <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <executions>
                 <execution>
                 <id>surefire-it</id>
                 <phase>integration-test</phase>
                 <goals>
                 <goal>test</goal>
                 </goals>
                 <configuration>
                 <skip>false</skip>
                 <systemProperties>
                 <property>
                 <name>cactus.contextURL</name>
                 <value>http://localhost:8080/catalog</value>
                 </property>
                 </systemProperties>
                 </configuration>
                 </execution>
                 </executions>
                 </plugin>
                 <plugin>
                 <groupId>org.codehaus.cargo</groupId>
                 <artifactId>cargo-maven2-plugin</artifactId>
                 <configuration>
                 <wait>false</wait>
                 <container>
                 <containerId>jboss4x</containerId>
                 <home>${env.JBOSS_HOME}</home>
                 <log>${basedir}/target/jboss4.0/cargo.log</log>
                 <output>${basedir}/target/jboss4.0/container.log</output>
                 </container>
                 <configuration>
                 <type>existing</type>
                 <home>${env.JBOSS_HOME}/server/test</home>
                 <properties>
                 <cargo.jboss.configuration>test</cargo.jboss.configuration>
                 </properties>
                 </configuration>
                 <deployer>
                 <deployables>
                 <deployable>
                 <location>${basedir}/target/deploy/${groupId}-app-${version}.ear</location>
                 </deployable>
                 </deployables>
                 </deployer>
                 </configuration>
                 <executions>
                 <execution>
                 <id>start-container</id>
                 <phase>pre-integration-test</phase>
                 <goals>
                 <goal>start</goal>
                 </goals>
                 </execution>
                 <execution>
                 <id>stop-container</id>
                 <phase>post-integration-test</phase>
                 <goals>
                 <goal>stop</goal>
                 </goals>
                 </execution>
                 </executions>
                 </plugin>
                
                 </plugins>
                 </build>
                 </profile>
                 </profiles>
                </project>