3 Replies Latest reply on Mar 17, 2013 4:52 AM by bmajsak

    Can you add a jar to a arquillian Java Archive

    martinnaughton

      Hello Guys,

                       This has been wrecking my head. I see that i can add jars to Enterprise and Web archive but i can not see that you can add a jar to a Java Archive. Does anyone have a small snippet of code how to do it?

       

      martin

        • 1. Re: Can you add a jar to a arquillian Java Archive
          bmajsak

          Well, like in the real world, you can't. But you can make uber-jar So just merge two jars into one - http://docs.jboss.org/shrinkwrap/1.0.0-cr-3/org/jboss/shrinkwrap/api/Archive.html#merge(org.jboss.shrinkwrap.api.Archive)

          • 2. Re: Can you add a jar to a arquillian Java Archive
            martinnaughton

            Hello Bartosz,

                                Thanks for the reply. I know the in Java world you can not but i was thinking you could in the Shrinkwrap world. Since you have to deploy one Java archive when doing your test. For example if i am running a test with a Java archive that relies on another external jar to run how can i add it to the Java archive so the test will run? This external jar will have to be deployed with the Java Archive.

             

            I have only seen simple code done with Java archives in Shrink wrap.

             

              @Deployment
                public static JavaArchive createDeployment() {
                    return ShrinkWrap.create(JavaArchive.class)
                        .addClass(Greeter.class)
                        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
                }
            
            • 3. Re: Can you add a jar to a arquillian Java Archive
              bmajsak

              Hi,

               

              you have several options here. You can rely on container modules (or shared libraries), so in the test you would simply assume that the required library is in the class path.

              Another option would be to deploy your test scenarion as another archive (such as WAR). Then you could simply add required JAR as library (there are addAsLibrary/adAsLibraries methods). But if you really want to combine library with your test you can simply use merge method as I've already suggested. So it could look like this:

              @Deployment
              public static JavaArchive createDeployment() {
                                 

                Archive<?> testArchive = ShrinkWrap.create(JavaArchive.class)
                                                   ...;

                Archive<?> library = ...  // Resolve it either using Maven resolver or load from file ShrinkWrap.createFromZipFile(type, archiveFile)

                return testArchive.merge(library);
              }


              Hope that helps.