1 Reply Latest reply on Feb 26, 2013 10:42 AM by gregn

    Arquillian test with Glassfish Embedded run in Eclipse but not Maven

    gregn Newbie

      We started integrating Arquillian into our tests and I've manged to get a @RunWith(Arquillian.class) test to run in Eclipse, but it fails when running in Maven with this exception:

       

      java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

              at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

       

      We're using the arquillian-glassfish-embedded-3.1 artifact v. 1.0.0.CR3.

       

      I'm running tests from maven using

       

      mvn clean test

       

      Here's a basic test that fails (the real test @Injects a backing controller, that all works when running in Eclipse, but I get the same RuntimeException with this). I originally had a @Deployment method here but that is unnecessary to cause the RuntimeException, apparently @RunWith(Arquillian.class) is enough.

       

      @RunWith(Arquillian.class)
      public class TestTest {
      
          @Test
          public void testTest() {
              Assert.assertTrue(true);
          }
      }
      

       

      Here's our arquillian.xml, the glassfish-resources.xml referenced just contains our DB connection information, which again, works in Eclipse.


      <?xml version="1.0" encoding="UTF-8"?>
      <arquillian xmlns="http://jboss.org/schema/arquillian"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
              http://jboss.org/schema/arquillian
              http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
          <container qualifier="glassfish-embedded" default="true">
              <configuration>
                  <property name="resourcesXml">src/test/resources/glassfish-resources.xml</property>
              </configuration>
          </container>
      </arquillian>
      

       

      Here's our pom.xml

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>com.application</groupId>
          <artifactId>Application</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <packaging>war</packaging>
      
          <name>application</name>
      
          <properties>
              <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      
              <slf4j.version>1.7.2</slf4j.version>
              <logback.version>1.0.9</logback.version>
          </properties>
      
          <dependencies>
              <dependency>
                  <groupId>javax</groupId>
                  <artifactId>javaee-web-api</artifactId>
                  <version>6.0</version>
                  <scope>provided</scope>
              </dependency>
              <dependency>
                  <groupId>org.glassfish</groupId>
                  <artifactId>javax.faces</artifactId>
                  <version>2.1.13</version>
              </dependency>
      
              <!-- Testing Dependencies -->
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.11</version>
                  <scope>test</scope>
              </dependency>
      
              <dependency>
                  <groupId>org.jboss.arquillian.junit</groupId>
                  <artifactId>arquillian-junit-container</artifactId>
                  <scope>test</scope>
              </dependency>
      
              <dependency>
                  <groupId>org.mockito</groupId>
                  <artifactId>mockito-all</artifactId>
                  <version>1.9.5</version>
                  <scope>test</scope>
              </dependency>
      
              <dependency>
                  <groupId>org.jboss.arquillian.container</groupId>
                  <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                  <version>1.0.0.CR3</version>
                  <scope>test</scope>
              </dependency>
      
              <!-- snip dependencies irrelevant to Glassfish and testing -->
      
          </dependencies>
      
          <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>org.jboss.arquillian</groupId>
                      <artifactId>arquillian-bom</artifactId>
                      <version>1.0.3.Final</version>
                      <scope>import</scope>
                      <type>pom</type>
                  </dependency>
              </dependencies>
          </dependencyManagement>
      
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>2.3.2</version>
                      <configuration>
                          <source>1.7</source>
                          <target>1.7</target>
                          <compilerArguments>
                              <endorseddirs>${endorsed.dir}</endorseddirs>
                          </compilerArguments>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <version>2.13</version>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-war-plugin</artifactId>
                      <version>2.1.1</version>
                      <configuration>
                          <failOnMissingWebXml>false</failOnMissingWebXml>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-dependency-plugin</artifactId>
                      <version>2.1</version>
                      <executions>
                          <execution>
                              <phase>validate</phase>
                              <goals>
                                  <goal>copy</goal>
                              </goals>
                              <configuration>
                                  <outputDirectory>${endorsed.dir}</outputDirectory>
                                  <silent>true</silent>
                                  <artifactItems>
                                      <artifactItem>
                                          <groupId>javax</groupId>
                                          <artifactId>javaee-endorsed-api</artifactId>
                                          <version>6.0</version>
                                          <type>jar</type>
                                      </artifactItem>
                                  </artifactItems>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
              <pluginManagement>
                  <plugins>
                      <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                      <plugin>
                          <groupId>org.eclipse.m2e</groupId>
                          <artifactId>lifecycle-mapping</artifactId>
                          <version>1.0.0</version>
                          <configuration>
                              <lifecycleMappingMetadata>
                                  <pluginExecutions>
                                      <pluginExecution>
                                          <pluginExecutionFilter>
                                              <groupId>org.apache.maven.plugins</groupId>
                                              <artifactId>maven-dependency-plugin</artifactId>
                                              <versionRange>[2.1,)</versionRange>
                                              <goals>
                                                  <goal>copy</goal>
                                              </goals>
                                          </pluginExecutionFilter>
                                          <action>
                                              <ignore></ignore>
                                          </action>
                                      </pluginExecution>
                                  </pluginExecutions>
                              </lifecycleMappingMetadata>
                          </configuration>
                      </plugin>
                  </plugins>
              </pluginManagement>
          </build>
      </project>
      

       

      Thanks for your help in advance, I feel like I've found a variety of solutions on this forum and others, but nothing is getting us past this exception.

        • 1. Re: Arquillian test with Glassfish Embedded run in Eclipse but not Maven
          gregn Newbie

          All right, I figured it out, turns out I was missing the glassfish-embedded-all artifact, which I had at one point but must have gotten lost in the shuffle or fixing something else. Order is also important.

           

          I also needed to make two profiles, one for Maven command line and one for Eclipse, because the glassfish-embedded-all artifact broke my Eclipse Junit test then!

           

          <profiles>
              <profile>
                  <id>eclipse</id>
                  <activation>
                      <activeByDefault>true</activeByDefault>
                  </activation>
                  <dependencies>
                      <dependency>
                          <groupId>javax</groupId>
                          <artifactId>javaee-web-api</artifactId>
                          <version>6.0</version>
                          <scope>provided</scope>
                      </dependency>
                      <dependency>
                          <groupId>org.glassfish</groupId>
                          <artifactId>javax.faces</artifactId>
                          <version>2.1.13</version>
                      </dependency>
                  </dependencies>
              </profile>
              
              <profile>
                  <id>cli</id>
                  <dependencies>
                      <dependency>
                          <groupId>org.glassfish.main.extras</groupId>
                          <artifactId>glassfish-embedded-all</artifactId>
                          <version>3.1.2.2</version>
                          <scope>provided</scope>
                      </dependency>
                      <dependency>
                          <groupId>javax</groupId>
                          <artifactId>javaee-web-api</artifactId>
                          <version>6.0</version>
                          <scope>provided</scope>
                      </dependency>
                      <dependency>
                          <groupId>org.glassfish</groupId>
                          <artifactId>javax.faces</artifactId>
                          <version>2.1.13</version>
                      </dependency>
                  </dependencies>
              </profile>
          </profiles>