4 Replies Latest reply on Mar 1, 2012 9:05 AM by jobame

    deployment fails for arquillian test with ClassNotFoundException

    jobame

      Hello,

       

      for a multi-module maven project with the stucture

       

      jat              <= main project
      `- jatentities  <= domain model
      `- jatdata      <= DAO's
      `- jatservice   <= services used e.g. by a customer
      `- jatpresent   <= presentation layer

       

      I wrote tests for the backing beans in the presentation layer. However, testCreateUser.war cannot be deployed. It seems with the war file the other resources are not included in the build but I cannot verify since the testCreateUser.war file is deleted right after the deployment failed.

       

      Without the test the application can be deployed and is working. When deploying the whole project to the server I am executing "mvn clean install" in the top project and then "mvn jboss-as:deploy" from within the presentation layer directory (jatpresent). For the test I am executing "mvn test -Parq-jbossasremote" from within the presentation layer directory (jatpresent). The following is the result (server.log).

       

      09:39:23,887 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.persistenceunit."testCreateUser.war#jatPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."testCreateUser.war#jatPU": Failed to start service
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: jatPU] class or package not found
      at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1400)
      at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1183)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1047)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:692)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
      ... 3 more
      Caused by: java.lang.ClassNotFoundException: de.dgo.domain.User from [Module "org.hibernate:main" from local module loader @ee22f7 (roots: D:\Daten\swd\jboss\jboss-as-7.1.0.Final\modules)]
      at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
      at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
      at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
      at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
      at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
      at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
      at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_26]
      at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_26]
      at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:170)
      at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1317)
      at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1389)
      ... 11 more
      09:39:24,137 INFO  [org.jboss.as.server] (management-handler-threads - 1) JBAS015870: Deploy of deployment "testCreateUser.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"testCreateUser.war#jatPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"testCreateUser.war#jatPU\": Failed to start service"}}

       

      What is missing? Is it just a maven usage problem (feeling a bit embarrassed )?

       

      I can paste some code if necessary.

       

      Regards,

       

      Michael

        • 1. Re: deployment fails for arquillian test with ClassNotFoundException
          bmajsak

          Hi Michael,

           

          if you can post your pom.xml, test class and arquillian.xml that would be very helpful to understand the problem.

           

          For the diagnosis what's in the WAR you can either print it explicilitly to the console using archive.toString(true) method or using this snippet in your arquillian.xml

           

          {code:xml}<engine>

            <property name="deploymentExportPath">target</property>

          </engine>{code}

           

          • 2. Re: deployment fails for arquillian test with ClassNotFoundException
            jobame

            In the test war only the test class, the class under test and persistence.xml are packaged.

             

            Now, for some reason, the exception is different.

             

            11:18:42,645 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."testCreateUser.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."testCreateUser.war".INSTALL: Failed to process phase INSTALL of deployment "testCreateUser.war"
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
            at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
            Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011446: Failed to add persistence unit service for jatPU
            at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:370)
            at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleWarDeployment(PersistenceUnitDeploymentProcessor.java:194)
            at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:118)
            at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.0.Final.jar:7.1.0.Final]
            ... 5 more
            Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.jboss.entityManagerFactory is already registered
            at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:227) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:307) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
            at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:345)
            ... 8 more

             

            arquillian.xml

             

            <?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">
              <engine>
               <property name="deploymentExportPath">target</property>
              </engine>
            <container qualifier="jboss" default="true">
              <protocol type="jmx-as7">
               <property name="executionType">REMOTE</property>
              </protocol>
              <configuration>
               <property name="jbossHome">d:/Programs/swd/jboss/jboss-as-7.1.0.Final/bin</property>
              </configuration>
            </container>
            </arquillian>

             

            pom.xml

             

            <?xml version="1.0"?>
            <project
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
            xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <modelVersion>4.0.0</modelVersion>
            <artifactId>jatpresent</artifactId>
            <packaging>war</packaging>
            <name>JavaServer Faces 2.0 - jatpresent</name>

            <parent>
              <artifactId>jat</artifactId>
              <groupId>de.dgo</groupId>
              <version>1.0</version>
            </parent>

            <properties>
              <myfaces.version>2.1.6</myfaces.version>
              <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
              <jboss.home>${env.JBOSS_HOME}</jboss.home>
            </properties>

            <dependencyManagement>
              <dependencies>
               <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-web-6.0</artifactId>
                <version>2.0.0.Final</version>
                <type>pom</type>
                <scope>import</scope>
               </dependency>
              </dependencies>
            </dependencyManagement>

            <dependencies>
              <dependency>
               <groupId>de.dgo</groupId>
               <artifactId>jatentities</artifactId>
               <version>${project.version}</version>
              </dependency>
              <dependency>
               <groupId>de.dgo</groupId>
               <artifactId>jatservice</artifactId>
               <version>${project.version}</version>
              </dependency>
              <dependency>
               <groupId>de.dgo</groupId>
               <artifactId>jatdata</artifactId>
               <version>${project.version}</version>
              </dependency>
              <dependency>
               <groupId>javax.enterprise</groupId>
               <artifactId>cdi-api</artifactId>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.jboss.spec.javax.annotation</groupId>
               <artifactId>jboss-annotations-api_1.1_spec</artifactId>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.jboss.spec.javax.ws.rs</groupId>
               <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.hibernate.javax.persistence</groupId>
               <artifactId>hibernate-jpa-2.0-api</artifactId>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.jboss.spec.javax.ejb</groupId>
               <artifactId>jboss-ejb-api_3.1_spec</artifactId>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-validator</artifactId>
               <version>4.2.0.Final</version>
               <scope>provided</scope>
               <exclusions>
                <exclusion>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-api</artifactId>
                </exclusion>
               </exclusions>
              </dependency>
              <dependency>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-jpamodelgen</artifactId>
               <version>1.1.1.Final</version>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>org.jboss.arquillian.junit</groupId>
               <artifactId>arquillian-junit-container</artifactId>
               <version>1.0.0.CR7</version>
               <scope>test</scope>
              </dependency>
              <dependency>
               <groupId>org.apache.myfaces.orchestra</groupId>
               <artifactId>myfaces-orchestra-core20</artifactId>
               <version>1.4</version>
              </dependency>
              <dependency>
               <groupId>org.apache.myfaces.core</groupId>
               <artifactId>myfaces-api</artifactId>
               <version>${myfaces.version}</version>
               <scope>compile</scope>
              </dependency>
              <dependency>
               <groupId>org.apache.myfaces.core</groupId>
               <artifactId>myfaces-impl</artifactId>
               <version>${myfaces.version}</version>
               <scope>compile</scope>
              </dependency>
              <dependency>
               <groupId>javax.servlet</groupId>
               <artifactId>servlet-api</artifactId>
               <version>2.5</version>
               <scope>provided</scope>
              </dependency>
              <dependency>
               <groupId>commons-el</groupId>
               <artifactId>commons-el</artifactId>
               <version>1.0</version>
              </dependency>
            </dependencies>

            <build>
              <finalName>${project.artifactId}</finalName>
              <defaultGoal>install</defaultGoal>
              <pluginManagement>
               <plugins>
                <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>2.3.2</version>
                 <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <encoding>ISO-8859-1</encoding>
                 </configuration>
                </plugin>
                <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-eclipse-plugin</artifactId>
                 <version>2.9</version>
                 <configuration>
                  <wtpversion>1.5</wtpversion>
                  <downloadSources>true</downloadSources>
                 </configuration>
                </plugin>
                <plugin>
                 <artifactId>maven-war-plugin</artifactId>
                 <version>2.2</version>
                 <configuration>
                  <failOnMissingWebXml>false</failOnMissingWebXml>
                 </configuration>
                </plugin>
               </plugins>
              </pluginManagement>
            </build>

            <developers>
              <developer>
               <name>Dominik Grupp</name>
               <organization>grupp-it.de</organization>
              </developer>
            </developers>

            <profiles>
              <profile>
               <id>default</id>
               <activation>
                <activeByDefault>true</activeByDefault>
               </activation>
               <build>
                <plugins>
                 <plugin>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.4.3</version>
                  <configuration>
                   <skip>true</skip>
                  </configuration>
                 </plugin>
                 <plugin>
                  <groupId>org.jboss.as.plugins</groupId>
                  <artifactId>jboss-as-maven-plugin</artifactId>
                  <version>7.1.0.Beta1b</version>
                 </plugin>
                </plugins>
               </build>
              </profile>

              <profile>
               <id>arq-jbossas-remote</id>
               <dependencies>
                <dependency>
                 <groupId>org.jboss.as</groupId>
                 <artifactId>jboss-as-arquillian-container-remote</artifactId>
                 <version>7.1.0.Final</version>
                 <scope>test</scope>
                </dependency>
               </dependencies>
               <repositories>
                <repository>
                 <id>jboss-public-repository</id>
                 <name>JBoss Repository</name>
                 <url>http://repository.jboss.org/nexus/content/groups/public</url>
                 <releases>
                  <enabled>true</enabled>
                 </releases>
                 <snapshots>
                  <enabled>false</enabled>
                 </snapshots>
                </repository>
               </repositories>
               <pluginRepositories>
                <pluginRepository>
                 <id>jboss-public-repository</id>
                 <name>JBoss Repository</name>
                 <url>http://repository.jboss.org/nexus/content/groups/public</url>
                 <releases>
                  <enabled>true</enabled>
                 </releases>
                 <snapshots>
                  <enabled>false</enabled>
                 </snapshots>
                </pluginRepository>
               </pluginRepositories>
              </profile>
            </profiles>

            </project>

             

            Testclass

             

            package de.dgo.gui.page;

            import static org.junit.Assert.assertNotNull;

            import org.jboss.arquillian.container.test.api.Deployment;
            import org.jboss.arquillian.core.api.annotation.Inject;
            import org.jboss.arquillian.junit.Arquillian;
            import org.jboss.shrinkwrap.api.Archive;
            import org.jboss.shrinkwrap.api.ShrinkWrap;
            import org.jboss.shrinkwrap.api.asset.EmptyAsset;
            import org.jboss.shrinkwrap.api.spec.WebArchive;
            import org.junit.Test;
            import org.junit.runner.RunWith;

            import de.dgo.domain.Department;
            import de.dgo.domain.User;
            import de.dgo.service.DepartmentService;

            @RunWith(Arquillian.class)
            public class CreateUserBeanTest {

             

            @Deployment
            public static Archive<?> createTestArchive() {
              return ShrinkWrap
                .create(WebArchive.class, "testCreateUser.war")
                .addClasses(TemperatureConverter.class)
                .addAsResource("META-INF/persistence.xml",
                  "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
            }

             

            @Inject
            private CreateUserBean createUser;

             

            @Inject
            private DepartmentService departmentService;

            @Test
            public void testConvertToCelsius() {
              Department department = departmentService.findById(1l);
             
              User user = createUser.getUser();
              user.setFirstname("Testfirstname");
              user.setLastname("Testlastname");
              user.setLoginname("Testlogin");
              user.setPwd("aaaaaaaa");
              user.setAdmin(false);
              user.setBarred(true);
              user.setDepartment(department);
             
              createUser.saveUser();
              assertNotNull(user.getId());
            }

            }

            • 3. Re: deployment fails for arquillian test with ClassNotFoundException
              bmajsak

              The problem is with your @Deployment method.

              You are adding just ".addClasses(TemperatureConverter.class)" whereas you should most likely add more classes, like Department, User and DepartmentService and all other dependencies needed to run your test (since it's targeted to managed / remote container). There is bunch of convenient methods in Shrinkwrap like .addPackage(true, User.class.getPackage()) which can add whole package recursively.

               

              Hope that helps.

               

               

               


              • 4. Re: deployment fails for arquillian test with ClassNotFoundException
                jobame

                ah - thank

                 

                I found out about adding the wrong class while you were posting but didn't realize about the resources.