14 Replies Latest reply on Dec 4, 2012 2:46 AM by kpiwko

    Deploying maven artifacts directly

    psychollek

      Yo,

       

      I need to deploy some artifacts (few of them in apropriate order), to perform testcase.

      I have all those artifacts on maven already (as ea and war archives) so it would be stupid to build them again and update tests for every time when something changes in their dependencies etc.
      As for now after search I found code to resolve maven artifacts and put them into archive I'm creating in Shrinkwrap - that would work for wars which can be embeded in ears but won't do for ears ;]
      So anybody knows how to do such a thing ?

        • 1. Deploying maven artifacts directly
          denis_k

          You may want to investigate org.jboss.shrinkwrap.api.spec.EnterpriseArchive interface to see what you can do with ears

          • 2. Deploying maven artifacts directly
            psychollek

            No no, you didn't uderstand ;] - I have ears in maven repo - I don't want to construct them - I want to deploy them directly .

            • 3. Re: Deploying maven artifacts directly
              aslak
              @Deployment
              public static EnterpriseArchive import()
              {
                        return DependencyResolvers.use(MavenDependencyResolver.class)
                                  .artifact("org.artifactid:groupid:ear:4.2.1.FINAL")
                                  .resolveAs(EnterpriseArchive.class);
              }
              

               

               

              ?

              • 4. Re: Deploying maven artifacts directly
                psychollek

                Thanks,

                 

                Could you point where some normal documentation, on the maven in shrinkwrap topic is ? or even where it should be - I think we could contribute some of our company time to write at aleast about our usecases.

                • 5. Re: Deploying maven artifacts directly
                  aslak

                  Currently ShrinkWrap only has JavaDoc, but I assume we'll end up with a Space on the new docs.jboss.org/author confluence instance in time.

                   

                  For now, you can always create a Article on the community space, http://community.jboss.org/en/shrinkwrap and we'll mix it into the docs when time comes..

                  • 6. Re: Deploying maven artifacts directly
                    psychollek

                    Ok, after some modifications to your code :

                     

                        @Deployment(order=1)
                        public static EnterpriseArchive getUserManager() {
                            return DependencyResolvers.use(MavenDependencyResolver.class).loadReposFromPom("pom.xml")
                                    .artifact("<groupId>:<artifactId>:ear:<version>")
                                    .resolveAs(EnterpriseArchive.class).iterator().next();
                        }
                    

                     

                    it somewhat works. It downloads the ear correctly, but than it complains about :

                     

                    java.lang.UnsupportedOperationException: Multiple WebArchives found in survey-application-1.0-SNAPSHOT.ear. Can not determine which to enrich

                     

                     

                    (of course it works flawlesly on normal deployment)

                    • 7. Re: Deploying maven artifacts directly
                      aslak

                      You just wanted the EAR deployed right? You don't want incontainer testing in the EAR itself ?

                       

                      The exception is, that unless you specify which WAR to enrich for incontainer testing, the Servlet Protocol can't figure it out, since the EAR contains multiple. (and it's lacking a way of specifying which to use atm)

                       

                      But if you only want it deployed, use @Deployment.testable = false

                      • 8. Re: Deploying maven artifacts directly
                        psychollek

                        Wellll, I want to inject ejb's which are part of this ear ... but let's say I can figure this out somehow.

                         

                        but why would container want to enrich any of my wars at all ?

                         

                        or why can't it enrich all of them ?

                        • 9. Re: Deploying maven artifacts directly
                          aslak

                          Injecting EJBs from another application is not a problem. You'll need to use @EJB.mappedName for the lookup but beyond that it should work as long as the Test deployment has the client libs or they share Class path or similar.

                           

                          To be able to execute tests incontainer, Arquillian needs to communicate with the Deployment somehow.. So in the case of the Servlet Protocol implementation, it needs to bundle along a Servlet. The Servlet is used by the client to forward the @Test execution request to the container, where the @Test is actually executed. It can only handle a single point of communication pr Deployment, hench it need to know which of the Wars it should enrich.

                           

                          In theory we could enrich all wars, but you would then need some kind of Qualifier on the @Test method to specify which War to hit. But we havn't looked at that yet.

                          • 10. Re: Deploying maven artifacts directly
                            psychollek

                            Wouldn't it be simpler to package test as a separate app and simply invoke it ?

                             

                            one would loose abiolity to inject local beans though.

                            • 11. Re: Deploying maven artifacts directly
                              aslak

                              Well, we can in theory support both. But you would loose the in deployment testing. as you say, local lookups and locally defined 'things'

                              • 12. Re: Deploying maven artifacts directly
                                aslak

                                or actaully, we do support both out of the box.

                                 

                                Define one @Deployment as testable=false which is your 'target' then define one that's testable=true which is only your testclasses etc..

                                • 13. Re: Deploying maven artifacts directly
                                  edevera

                                  This post seems a bit old and I guess the MavenResolver way has been replaced by Maven.resolver one.

                                   

                                  How do I have to deploy an ear (available in my maven repository) now?

                                   

                                  Thanks.

                                  • 14. Re: Deploying maven artifacts directly
                                    kpiwko

                                    Hi Eduardo,

                                     

                                    exactly the same way, although the API is a bit different now.

                                    Follow this document: https://community.jboss.org/wiki/HowToIAddMavenArtifactsToMyShrinkWrapArchives

                                     

                                    Your call would look like:

                                     

                                    Maven.resolver() // get resolver instance
                                     .resolve("groupId:artifactId:ear:version") // get EAR from Maven repository - note you might want to set your own Maven repository first via document above
                                     .withoutTransitivity() // you don't need any ear's transitive deps
                                     .asSingle(EnterpriseArchive.class); // wrap the result as single object of type EnterpriseArchive
                                    
                                    

                                     

                                    HTH,

                                     

                                    Karel