4 Replies Latest reply on Aug 29, 2011 9:21 AM by aslak

    Adding all files from a directory to an archive

    htfv

      Hello World!

       

      I want to add a bunch of files from a directory in my project to the deployed archive, but I coudn't find any simple way to do it. In my case, I want to deploy a bunch of JSP's for testing as Web resources, but I can imagine that people may want package resources in JAR as well. Currently, I use addAsWebResource, but there are 2 things that I don't like about it:

       

      • I have to list every file I want to deploy;
      • ClassLoader is used to load resources (I think both points are somehow related )).

       

      Am I missing something? Or is there really no way to simply add all files from a directory?

        • 1. Re: Adding all files from a directory to an archive
          aslak

          In the later ShrinkWrap versions you can do

           

          addAsWebReosurce(new FIle("some directory"))

           

          that should recursivly add the directory content..

          • 2. Re: Adding all files from a directory to an archive
            htfv

            It does not work. I checked ShrinkWraps source - File is simply wrapped (without any extra checks) in FileAsset which may return only one stream. Also, addAsWebResource for directory is strange, I would expect addAsWebResources (plural).

            • 3. Re: Adding all files from a directory to an archive
              booking59

              This worked for me :

              WebArchive war = ShrinkWrap.create(WebArchive.class)

                              .addPackages(true, "test")

                              .addAsResource("test-persistence", ArchivePaths.create("META-INF/persistence"))

                              .setWebXML(new StringAsset(webXml.contextParam(

                                              ProjectStage.PROJECT_STAGE_PARAM_NAME,

                                              ProjectStage.Development).exportAsString()))

                              .as(ExplodedImporter.class)

                              .importDirectory("src/main/webapp")

                              .as(WebArchive.class);

              • 4. Re: Adding all files from a directory to an archive
                aslak

                Which shrinkwrap and arquillian version are you using?