4 Replies Latest reply on Mar 7, 2016 10:10 AM by Sanket Patel

    Creating an ear file using Shrinkwrap using the pom's of a multi-module maven project

    Dominik Grupp Newbie

      Hi,

       

      from our maven multi-module project we try to generate an ear archive with Shrinkwrap. The structure is as follows (see ear-POM below for an example).

       

      ab23Bear

              ab23BearCommon

              ab23BearDomain

              ab23BearEAR

              ab23BearEJB

              ab23BearService

              ab23BearWeb

       

      There are many examples out there for archive generation but we don't manage to combine them properly. Will we have to create each module separately as jar/war and then combine them into the ear with addAsModule/addAsLibrary? That would result in a quite big and complex method and if some source files / packages are moved then the method has to be modified again. That seems to be rather error-prone.

       

      In quite a few examples MavenDependencyResolver but we couldn't find it documented. Is the API documented for MavenDependencyResolver? The most actual version on the web is ShrinkWrap API 1.0.0-cr-3 API (http://docs.jboss.org/shrinkwrap/1.0.0-cr-3/) which does not include that class. Where is it documented?

       

      It seems the examples follow different approaches and we are unsure on how to apply it to our project structure. Would we have e.g. a src/test/resources/arquillian-dep.xml (as described in e.g. https://community.jboss.org/thread/202264)

       

      <?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/xsd/maven-4.0.0.xsd">
                <modelVersion>4.0.0</modelVersion>
                <parent>
                          <groupId>de.ab23.bear</groupId>
                          <artifactId>ab23Bear</artifactId>
                          <version>1.0-SNAPSHOT</version>
                </parent>
                <artifactId>de.as24.billing.testdependencies</artifactId>
      </project>
      

       

      and a deployment method like the following?

       

      @Deployment(testable = true)
                public static EnterpriseArchive createDeployment() {
        
                          String pom = GreeterTest.class.getResource("/arquillian-deps.xml").getFile();
              MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("classpath:arquillian-deps.xml").importAllDependencies().resolveAs(EnterpriseArchive.class);
                          EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "as24BillingTest.ear");
                          ear.addAsLibraries(resolver.artifact("de.ab23.bear:ab23Bear:1.0-SNAPSHOT").resolveAsFiles());
      
      
                          System.out.println(ear.toString(true));
        
                          return ear;
                }
      

       

      This, however, currently does not compile due to "org.jboss.shrinkwrap.resolver.api.ResolverEntryPoint cannot be resolved. It is indirectly referenced from required .class files".

       

      Could anybody please point us into the right direction? Is there a rather conrete and best-practice example around?

       

      <?xml version="1.0"?>
      <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>
                <parent>
                       <groupId>de.ab23.bear</groupId>
                       <artifactId>ab23Bear</artifactId>
                       <version>1.0-SNAPSHOT</version>
                </parent> 
                <artifactId>ab23BearEAR</artifactId>
                <packaging>ear</packaging>
        
                <properties>
                       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                </properties>
        
                <dependencies>
                          <dependency>
                                    <groupId>de.ab23.bear</groupId>
                                    <artifactId>ab23BearCommon</artifactId>
                          </dependency>
                          <dependency>
                                    <groupId>de.ab23.bear</groupId>
                                    <artifactId>ab23BearDomain</artifactId>
                          </dependency>
                          <dependency>
                                    <groupId>de.ab23.bear</groupId>
                                    <artifactId>ab23BearEJB</artifactId>
                                    <type>ejb</type>
                          </dependency>
                          <dependency>
                                    <groupId>de.ab23.bear</groupId>
                                    <artifactId>ab23BearService</artifactId>
                          </dependency>
                          <dependency>
                                    <groupId>de.ab23.bear</groupId>
                                    <artifactId>ab23BearWeb</artifactId>
                                    <type>war</type>
                          </dependency>
                </dependencies>
      
                 <build>
                          <plugins>
                                    <plugin>
                                              <groupId>org.apache.maven.plugins</groupId>
                                              <artifactId>maven-ear-plugin</artifactId>
                                              <version>2.8</version>
                                              <configuration>
                                                        <defaultLibBundleDir>lib</defaultLibBundleDir>
                                                        <modules>
                                                                  <jarModule>
                                                                            <groupId>de.ab23.bear</groupId>
                                                                            <artifactId>ab23BearCommon</artifactId>
                                                                            <includeInApplicationXml>false</includeInApplicationXml>
                                                                            <bundleFileName>ab23BearCommon.jar</bundleFileName>
                                                                  </jarModule>
                                                                  <jarModule>
                                                                            <groupId>de.ab23.bear</groupId>
                                                                            <artifactId>ab23BearDomain</artifactId>
                                                                            <includeInApplicationXml>false</includeInApplicationXml>
                                                                            <bundleFileName>ab23BearDomain.jar</bundleFileName>
                                                                  </jarModule>
                                                                  <jarModule>
                                                                            <groupId>de.ab23.bear</groupId>
                                                                            <artifactId>ab23BearService</artifactId>
                                                                            <includeInApplicationXml>false</includeInApplicationXml>
                                                                            <bundleFileName>ab23BearService.jar</bundleFileName>
                                                                  </jarModule>
                                                                  <webModule>
                                                                            <groupId>de.ab23.bear</groupId>
                                                                            <artifactId>ab23BearWeb</artifactId>
                                                                            <bundleFileName>ab23BearWeb.war</bundleFileName>
                                                                  </webModule>
                                                                  <ejbModule>
                                                                            <groupId>de.ab23.bear</groupId>
                                                                            <artifactId>ab23BearEJB</artifactId>
                                                                            <bundleFileName>ab23BearEJB.jar</bundleFileName>
                                                                  </ejbModule>
                                                        </modules>
                                              </configuration>
                                    </plugin>
                                    <plugin>
                                              <groupId>org.jboss.as.plugins</groupId>
                                              <artifactId>jboss-as-maven-plugin</artifactId>
                                              <configuration>
                                                        <skip>false</skip>
                                              </configuration>
                                    </plugin>
                          </plugins>
                </build>
        </project>
      
        • 1. Re: Creating an ear file using Shrinkwrap using the pom's of a multi-module maven project
          Dominik Grupp Newbie

          My previous question probably was to general - so here a more detailed question. Based on https://community.jboss.org/wiki/HowToIAddMavenArtifactsToMyShrinkWrapArchives we use

           

          [...]
          File[] libsDomain = Maven.resolver().loadPomFromFile("pom.xml").resolve("de.ab23.bear:ab23BearDomain").withTransitivity().asFile();
          EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "ab23BearTest.ear").addAsLibraries(libsDomain);
          [...]
          

           

          However, that gives us the following exception. The POMs look exactly as stated in the above link except as version for the shrinkwrap.resolver we use 2.0.0-beta-2.

           

          What do we have to change in the POM (or code?) to include the above dependency?

           

          java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.EnterpriseArchive de.ab23.dao.bear.AccountStateDaoTest.createDeployment()
                    at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:160)
                    at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:94)
                    at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:57)
                    at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                    at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
                    at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
                    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
                    at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                    at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
                    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
                    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
                    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
                    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:80)
                    at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
                    at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
                    at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
                    at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
                    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
                    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
                    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
                    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
          Caused by: java.lang.reflect.InvocationTargetException
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:156)
                    ... 50 more
          Caused by: java.lang.RuntimeException: Could not create object from user view
                    at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:95)
                    at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:54)
                    at org.jboss.shrinkwrap.resolver.api.Resolvers.use(Resolvers.java:67)
                    at org.jboss.shrinkwrap.resolver.api.maven.Maven.resolver(Maven.java:37)
                    at de.ab23.dao.bear.AccountStateDaoTest.createDeployment(AccountStateDaoTest.java:41)
                    ... 55 more
          Caused by: java.lang.reflect.InvocationTargetException
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at org.jboss.shrinkwrap.resolver.api.ResolverSystemFactory.createFromUserView(ResolverSystemFactory.java:91)
                    ... 59 more
          Caused by: java.lang.IllegalStateException: There is more then a one service for serviceClass org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem
                    at org.jboss.shrinkwrap.resolver.spi.loader.SpiServiceLoader.onlyOne(SpiServiceLoader.java:88)
                    at org.jboss.shrinkwrap.resolver.spi.loader.ServiceRegistry.onlyOne(ServiceRegistry.java:117)
                    ... 64 more
          
          
          • 3. Re: Creating an ear file using Shrinkwrap using the pom's of a multi-module maven project
            Dominik Grupp Newbie

            Regarding the above error message I cannot say in detail how me solved it. However, we got it to work but did not use the pom to include the dependencies. Instead, we used the standard approach to include our own classes from all modules we needed for the test. So the deployment factory class just included a war file as a container for all those classes. No dependencies were added specifically.