4 Replies Latest reply: Jan 14, 2010 11:17 AM by jaikiran pai RSS

Add a directory resource to the JavaArchive

jaikiran pai Master

I am using the http://docs.jboss.org/shrinkwrap/1.0.0-alpha-3/api/org/jboss/shrinkwrap/api/container/ResourceContainer.html#addResource(java.io.File,%20java.lang.String) API to add a directory (containing files, sub-directories etc...) to a JavaArchive:


if (TEST_SRC_RESOURCES.exists())
    //replace the "." with "/" in the packagename
    String resourceRelativePath = testPackage.getName().replaceAll("\\.", "/");
    File resourceAbsolutePath = new File(TEST_SRC_RESOURCES, resourceRelativePath);
    if (resourceAbsolutePath.exists())
        // add all files, folders, sub-folders under this location to the root of the archive
    jar.addResource(resourceAbsolutePath, Paths.root());


Nothing fancy in the code. The API javadocs doesn't mention that only regular files are supported, so i assumed even directories are allowed. But on running this code, i get:


Caused by: java.io.FileNotFoundException: /home/me/my-resources-dir (Is a directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at org.jboss.shrinkwrap.impl.base.asset.FileAsset.openStream(FileAsset.java:69)
    ... 35 more


Are directories expected to work with this API? If not, is there any other API which i can use to do this?