4 Replies Latest reply on May 14, 2012 8:25 AM by rune_rne

    Adding dependencies to .jar in arquillian

    rune_rne

      hi,

      i try to write some integration test in these test i try to use some .jar files as libraries for the functions i want to test.

      I do this in eclipse without mave using ivy.

       

      my bean looks like this:

      @Stateless
      public class TestBean{
           static{
                  PceLogger newLogger = new PceLogger();
           }
      
            public static void testDia(){
                 newLogger.something();
            }
       }
      

      my test looks like this:

       

      @Deployment
       public static WebArchive createTestArchive() {
      
        MavenDependencyResolver resolver = DependencyResolvers
                      .use(MavenDependencyResolver.class);
      
       WebArchive war = ShrinkWrap.create(WebArchive.class, "TestBean.war").addClass(TestBean.class)
       .addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class)
       .artifacts("/WEB-INF/lib/A.jar","/WEB-INF/lib/B.jar","/WEB-INF/lib/C.jar").resolveAs(WebArchive.class))
      
       .addAsManifestResource(EmptyAsset.INSTANCE,ArchivePaths.create("beans.xml"))
       .addAsManifestResource("newTest/web.war/META-INF/MANIFEST.MF");
       return war;
      
       }
      
       @EJB
       private TestBean testBean;
      
       @Test
       public void test() throws Exception {
           Assert.assertNotNull(testBean);
       }
      
      

       

      Further i put the jar into the build path and aswell i tried to put the path into the MANIFEST

      i already tried to run the deployment with:

      .addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class)

      .artifacts("/WEB-INF/lib/A.jar","/WEB-INF/lib/B.jar","/WEB-INF/lib/C.jar").resolveAs(WebArchive.class))

       

      which results in:

      java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive JunitTestCase.createTestArchive()

       

      Caused by: java.lang.reflect.InvocationTargetException

       

      Caused by: org.jboss.shrinkwrap.resolver.api.ResolutionException: Bad artifact coordinates, expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]][:<version>]

       

      and with

      .addAsLibraries("/WEB-INF/lib/A.jar","/WEB-INF/lib/B.jar","/WEB-INF/lib/C.jar").resolveAs(WebArchive.class))

       

      which results in the same

       

       

      when i run it wihtout the addAsLibraries i get:

      Failed to start service jboss.deployment.unit."TestBean.war".

      Caused by: java.lang.NoClassDefFoundError:

       

      but it is not working

      any suggestions?

        • 1. Re: Adding dependencies to .jar in arquillian
          alrubinger

          Looks like you're trying to use the ShrinkWrap Maven Resolver to simply add existing files to your WebArchive?  The Resolver actually "resolves" Maven coordinates like "junit:junit:4.10" into archives; if you already have the files, use ZipImporter instead.

           

          S,

          ALR

          • 2. Re: Adding dependencies to .jar in arquillian
            rune_rne

            yes you are right i already have the files. do i need to  merge all the files? i tried but it seems that only on import ist working?

            further i have to  add TestBean via addClass right? but this is not working for the ZipImporter.class

            • 3. Re: Adding dependencies to .jar in arquillian
              rune_rne

              i tried it like this but i do not think it is a good solution and i m not sure if it is working still getting an exception

               

              WebArchive imported = ShrinkWrap.create(ZipImporter.class,"Test").importFrom(new File("bin/org/blog/bean/Jar1.jar")).as(WebArchive.class);

              WebArchive imported1 = ShrinkWrap.create(ZipImporter.class,"Tes1t").importFrom(new File("bin/org/blog/bean/Jar2".jar")).as(WebArchive.class);

              WebArchive imported2 = ShrinkWrap.create(ZipImporter.class,"Test2").importFrom(new File("bin/org/blog/bean/Jar3".jar")).as(WebArchive.class);

              imported.merge(imported1);

              imported.merge(imported2);

               

              WebArchive war = ShrinkWrap.create(WebArchive.class, "TestBean.war").addClass(TestBean.class)

              .addAsManifestResource(EmptyAsset.INSTANCE,ArchivePaths.create("beans.xml"));

              war.merge(imported);

              • 4. Re: Adding dependencies to .jar in arquillian
                rune_rne

                i get the following error now:

                 

                14:16:51,802 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."TestBean.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."TestBean.war".POST_MODULE: Failed to process phase POST_MODULE of deployment "TestBean.war"

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.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_19]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_19]

                at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_19]

                 

                Caused by: java.lang.RuntimeException: Error getting reflective information for class org.blog.bean.TestBean with ClassLoader ModuleClassLoader for Module "deployment.TestBean.war:main" from Service Module Loader

                at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)

                at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)

                at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)

                at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)

                at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                ... 5 more

                Caused by: java.lang.NoClassDefFoundError: IPceAppender

                at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.6.0_19]

                at java.lang.Class.privateGetDeclaredFields(Class.java:2291) [rt.jar:1.6.0_19]

                at java.lang.Class.getDeclaredFields(Class.java:1743) [rt.jar:1.6.0_19]

                at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                 

                 

                Caused by: java.lang.ClassNotFoundException: PceAppender from [Module "deployment.TestBean.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)

                 

                it seams that jboss cant find the dependencies during the deployment. i put the dependencies into the build path of eclipse and into the manifest  the jar files exist in a folder in web-inf/lib

                but it still cant find it