0 Replies Latest reply on Jun 15, 2012 4:01 AM by dr.cheesecake

    How to load resources from a jar

    dr.cheesecake Newbie

      Hi,

       

      I tryed to load a xml file from a jar which I deploy on a JBoss AS 7.1.1.Final.

       

      I tryed the normal Java way:

       

      InputStream mockupdata = MyClazz.getClassLoader().getResourceAsStream("my.pack.MockupData.xml");

       

      This returns null.

       

      Debugging shows me that I get a org.jboss.modules.ModuleClassLoader which extends org.jboss.modules.ConcurrentClassLoader

       

      The ConcurrentClassLoader implements the getResourceAsStream method. This is the method in the jboss-modules-1.1.1.GA.jar:

       

      public final InputStream getResourceAsStream(final String name) {

              for (String s : Module.systemPaths) {

                  if (name.startsWith(s)) {

                      return definingLoader != null ? definingLoader.getResourceAsStream(name) : ClassLoader.getSystemResourceAsStream(name);

                  }

              }

              return findResourceAsStream(name, false);

          }

       

      The systemPaths are "java.", "sun.reflect." and "__redirected.". So these are not my packages. findResourceAsStream() is this Method:

       

      protected InputStream findResourceAsStream(final String name, final boolean exportsOnly) {

              final URL url = findResource(name, exportsOnly);

              try {

                  return url == null ? null : url.openStream();

              } catch (IOException e) {

                  return null;

              }

          }

       

      And findResource() is this method:

       

      protected URL findResource(final String name, final boolean exportsOnly) {

              return null;

          }

       

       

      So it is not possible to load resources with this functionalty and I don't know another way. How to load resources within a jar on JBoss AS 7?