2 Replies Latest reply on Aug 27, 2012 4:22 PM by Paulo Henrique Lerbach Rodrigues

    Problem when deploying war file with maven dependencies

    Paulo Henrique Lerbach Rodrigues Newbie

      Dear friends, I'm having problem when trying to test, my sources:

       

      pom:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <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/maven-v4_0_0.xsd">
                <modelVersion>4.0.0</modelVersion>
                <parent>
                          <artifactId>agenda</artifactId>
                          <groupId>br.com.fourlinux</groupId>
                          <version>1.0</version>
                          <relativePath>../agenda</relativePath>
                </parent>
                <artifactId>agenda-ejb</artifactId>
                <packaging>ejb</packaging>
                <name>agenda EJB module</name>
      
      
                <properties>
                          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                </properties>
      
      
                <!-- Digamos ao Maven qual versão do artefato utilizar! -->
                <!-- Assim ele saberá quais dependências transitivas utilizar! -->
                <dependencyManagement>
                          <dependencies>
                                    <dependency>
                                              <groupId>org.jboss.arquillian</groupId>
                                              <artifactId>arquillian-bom</artifactId>
                                              <version>1.0.2.Final</version>
                                              <scope>import</scope>
                                              <type>pom</type>
                                    </dependency>
                          </dependencies>
                </dependencyManagement>
      
      
                <dependencies>
                          <dependency>
                                    <groupId>org.jboss.spec</groupId>
                                    <artifactId>jboss-javaee-6.0</artifactId>
                                    <version>1.0.0.Final</version>
                                    <type>pom</type>
                                    <scope>provided</scope>
                          </dependency>
                          <!-- Dependência de SGBD -->
                          <dependency>
                                    <groupId>hsqldb</groupId>
                                    <artifactId>hsqldb</artifactId>
                                    <version>1.8.0.10</version>
                                    <scope>compile</scope>
                          </dependency>
                          <!-- Test scope dependencies -->
                          <dependency>
                                    <groupId>junit</groupId>
                                    <artifactId>junit</artifactId>
                                    <scope>test</scope>
                          </dependency>
                          <!-- Juntando as dependências do Arguilian e Junit -->
                          <!-- Necessário para utilizarmos os dois juntos -->
                          <dependency>
                                    <groupId>org.jboss.arquillian.junit</groupId>
                                    <artifactId>arquillian-junit-container</artifactId>
                                    <scope>test</scope>
                          </dependency>
                          <dependency>
                                    <groupId>org.jboss.shrinkwrap.resolver</groupId>
                                    <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
                                    <scope>test</scope>
                          </dependency>
                          <dependency>
                                    <groupId>org.slf4j</groupId>
                                    <artifactId>slf4j-simple</artifactId>
                                    <version>1.6.4</version>
                                    <scope>test</scope>
                          </dependency>
                </dependencies>
      
      
                <profiles>
                          <profile>
                                    <id>arquillian-jbossas-remote</id>
                                    <dependencies>
                                              <!-- Provided scope dependencies -->
                                              <dependency>
                                                        <groupId>org.jboss.as</groupId>
                                                        <artifactId>jboss-as-arquillian-container-remote</artifactId>
                                                        <version>7.1.1.Final</version>
                                                        <scope>test</scope>
                                              </dependency>
                                              <dependency>
                                                        <groupId>org.jboss.arquillian.protocol</groupId>
                                                        <artifactId>arquillian-protocol-servlet</artifactId>
                                                        <scope>test</scope>
                                              </dependency>
                                    </dependencies>
                          </profile>
                </profiles>
      
      
                <build>
                          <plugins>
                                    <plugin>
                                              <groupId>org.apache.maven.plugins</groupId>
                                              <artifactId>maven-compiler-plugin</artifactId>
                                              <configuration>
                                                        <source>1.6</source>
                                                        <target>1.6</target>
                                                        <compilerArgument>-J -Xss10M</compilerArgument>
                                              </configuration>
                                    </plugin>
                                    <!-- Adicionemos o Plugin abaixo para garantir -->
                                    <!-- A ultima versão do maven surefire -->
                                    <plugin>
                                              <artifactId>maven-surefire-plugin</artifactId>
                                              <version>2.12</version>
                                    </plugin>
                                    <plugin>
                                              <groupId>org.apache.maven.plugins</groupId>
                                              <artifactId>maven-ejb-plugin</artifactId>
                                              <version>2.3</version>
                                              <configuration>
                                                        <ejbVersion>3.1</ejbVersion>
                                                        <archive>
                                                                  <manifest>
                                                                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                                                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                                                  </manifest>
                                                        </archive>
                                              </configuration>
                                    </plugin>
                          </plugins>
                </build>
      </project>
      
      

       

      My test:

       

       

      package br.com.fourlinux.agenda.servico;
      
      
      import java.io.File;
      
      
      import javax.ejb.EJB;
      import javax.inject.Inject;
      
      
      import junit.framework.Assert;
      
      
      import org.jboss.arquillian.container.test.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.arquillian.junit.InSequence;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.jboss.shrinkwrap.resolver.api.DependencyResolvers;
      import org.jboss.shrinkwrap.resolver.api.maven.MavenDependencyResolver;
      import org.jboss.shrinkwrap.resolver.api.maven.filter.ScopeFilter;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      
      import br.com.fourlinux.agenda.dominio.Contato;
      import br.com.fourlinux.agenda.dominio.repositorio.ContatoRepository;
      import br.com.fourlinux.agenda.dominio.repositorio.ContatoRepositoryImpl;
      import br.com.fourlinux.agenda.infra.dao.ContatoDAO;
      import br.com.fourlinux.agenda.infra.dao.ContatoJPADAO;
      import br.com.fourlinux.agenda.infra.dao.DAOFactory;
      import br.com.fourlinux.agenda.infra.dao.GenericDAO;
      import br.com.fourlinux.agenda.infra.dao.GenericJPADAO;
      
      
      @RunWith(Arquillian.class)
      public class AgendaTest {
      
      
                @Deployment
                public static WebArchive createDeployment() {
      
      
                          File persistencexml = new File("src/main/resources/META-INF/persistence.xml");
                          File beansxml = new File("src/main/resources/META-INF/beans.xml");
      
      
                          MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class)
                                                                                                                                                                      .includeDependenciesFromPom("pom.xml");
      
      
                          WebArchive ja = ShrinkWrap.create(          WebArchive.class,
                                                                                                                    "test.war")
                                                                                                .addClasses(Agenda.class,
                                                                                                                              ContatoRepository.class,
                                                                                                                              ContatoRepositoryImpl.class,
                                                                                                                              Contato.class,
                                                                                                                              ContatoDAO.class,
                                                                                                                              DAOFactory.class,
                                                                                                                              GenericDAO.class,
                                                                                                                              ContatoJPADAO.class,
                                                                                                                              GenericJPADAO.class)
                                                                                                .addAsManifestResource(persistencexml)
                                                                                                .addAsManifestResource(beansxml)
                                                                                                .addAsLibraries(resolver.resolveAsFiles(new ScopeFilter("compile")));
      
      
                          System.out.println(ja.toString(true));
      
      
                          return ja;
                }
      
      
                @Inject
                Agenda                                        agenda;
      
      
                @EJB
                ContatoRepository          repo;
      
      
                @Test
                @InSequence(1)
                public void salvarContatoDeveSalvarContato() {
      
      
                          Contato c1 = new Contato();
      
      
                          c1.setNome("PH");
                          c1.setTelefone("33218181");
      
      
                          Contato c2 = new Contato();
      
      
                          c2.setNome("Tatá");
                          c2.setTelefone("33213030");
      
      
                          agenda.salvarContato(c1);
      
      
                          Assert.assertEquals(1, repo.listarContatos().size());
      
      
                          agenda.salvarContato(c2);
      
      
                          Assert.assertEquals(2, repo.listarContatos().size());
      
      
                }
      
      
                @Test
                @InSequence(2)
                public void salvarContatoDeveSerPersistente() {
      
      
                          Assert.assertEquals(2, repo.listarContatos().size());
      
      
                }
      
      
      }
      

       

      The problem stacktrace:

       

      java.lang.NoClassDefFoundError: org/jboss/shrinkwrap/resolver/api/DependencyResolutionFilter
                at java.lang.Class.getDeclaredConstructors0(Native Method)
                at java.lang.Class.privateGetDeclaredConstructors(Class.java:2406)
                at java.lang.Class.getConstructors(Class.java:1476)
                at org.junit.runners.model.TestClass.<init>(TestClass.java:36)
                at org.junit.runners.ParentRunner.<init>(ParentRunner.java:73)
                at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
                at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:50)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
                at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
                at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
                at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
                at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
                at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
                at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
                at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
                at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:33)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
                at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethodInternal(JMXTestRunner.java:129)
                at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethod(JMXTestRunner.java:108)
                at org.jboss.as.arquillian.service.ArquillianService$ExtendedJMXTestRunner.runTestMethod(ArquillianService.java:226)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at java.lang.reflect.Method.invoke(Method.java:616)
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:111)
                at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:45)
                at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:226)
                at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
                at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:251)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:857)
                at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:795)
                at org.jboss.as.jmx.PluggableMBeanServerImpl$TcclMBeanServer.invoke(PluggableMBeanServerImpl.java:498)
                at org.jboss.as.jmx.PluggableMBeanServerImpl.invoke(PluggableMBeanServerImpl.java:246)
                at org.jboss.remotingjmx.protocol.v1.ServerProxy$InvokeHandler.handle(ServerProxy.java:1034)
                at org.jboss.remotingjmx.protocol.v1.ServerProxy$MessageReciever$1.run(ServerProxy.java:215)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                at java.lang.Thread.run(Thread.java:679)
      Caused by: java.lang.ClassNotFoundException: org.jboss.shrinkwrap.resolver.api.DependencyResolutionFilter from [Module "deployment.test.war:main" from Service Module Loader]
                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)
                ... 41 more
      

       

      What I'm doing wrong?

       

      Thx,

      PH

        • 1. Re: Problem when deploying war file with maven dependencies
          Karel Piwko Master

          Hello Paulo,

           

          first, Shrinkres has a BOM file and Depchain as well. It is much easier to use them, such as:

           

          <dependencyManagement>
                  <dependencies>
          
          
                      <!-- We use development version of ShrinkWrap Maven Resolver --> 
                      <dependency>
                          <groupId>org.jboss.shrinkwrap.resolver</groupId>
                          <artifactId>shrinkwrap-resolver-bom</artifactId>
                          <version>${version.org.jboss.shrinkwrap.resolver}</version>
                          <type>pom</type>
                          <scope>import</scope>
                      </dependency>
          
                     ....
          
          
                  </dependencies>
          </dependencyManagement>
          
          <dependency>
                      <groupId>org.jboss.shrinkwrap.resolver</groupId>
                      <artifactId>shrinkwrap-resolver-depchain</artifactId>
                      <type>pom</type>
                      <scope>test</scope>
                      <version>${version.org.jboss.shrinkwrap.resolver}</version>
          </dependency>
          
          
          

           

          Note, preferred version is 2.0.0-alpha-1 because of the fixes included there.

           

          Second, in order to include all test scoped dependencies, you have to first load the pom.xml and the select what you want to include, e.g.:

           

           

          DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("pom.xml")
                                  .importTestDependencies().resolveAs(JavaArchive.class));
          
          

           

          HTH,

           

          Karel

          • 2. Re: Problem when deploying war file with maven dependencies
            Paulo Henrique Lerbach Rodrigues Newbie

            Dear Karel Piwko, thanks for your response!

             

            I will evaluate after the sugestions.

             

            Thx,

            PH