4 Replies Latest reply on Oct 24, 2011 4:09 AM by thomas.diesler

    Using VFS to load an embedded bundle resource not working?

    tpesce

      I feel like I'm missing something... I'm trying a relatively simple operation with VFS that seems like it should work. I'm using JBoss AS 7.0.2.

       

      First, I've added these to the list of modules in the standalone configuration:

       

      {code}<module identifier="org.jboss.vfs"/>

      <module identifier="org.jboss.osgi.vfs" startlevel="1"/>{code}

       

      In my Activator this works:

       

      {code}URL resource = getClass().getClassLoader().getResource("files/hello.txt");

      InputStream stream = resource.openStream();{code}

       

      But this:

       

      {code}URL resource = getClass().getClassLoader().getResource("files/hello.txt");

      VirtualFile file = VFS.getChild(resource.toURI());

      InputStream stream = file.openStream();{code}

       

      throws a FileNotFoundException:

       

      {noformat}23:42:33,902 ERROR [stderr] (MSC service thread 1-1) java.io.FileNotFoundException: /files/hello.txt (No such file or directory)

      23:42:33,903 ERROR [stderr] (MSC service thread 1-1)           at java.io.FileInputStream.open(Native Method)

      23:42:33,903 ERROR [stderr] (MSC service thread 1-1)           at java.io.FileInputStream.<init>(FileInputStream.java:120)

      23:42:33,904 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.vfs.spi.RootFileSystem.openInputStream(RootFileSystem.java:55)

      23:42:33,904 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.vfs.VirtualFile.openStream(VirtualFile.java:238)

      23:42:33,904 ERROR [stderr] (MSC service thread 1-1)           at bundle.Activator.start(Activator.java:32)

      23:42:33,905 ERROR [stderr] (MSC service thread 1-1)           at org.jboss.osgi.framework.internal.HostBundleState.transitionToActive(HostBundleState.java:295){noformat}