3 Replies Latest reply on Aug 20, 2003 3:40 AM by dinesh_soma

    getResourceAsStream() from jar in lib folder failing

    dinesh_soma

      Folks,
      I have a 'ear' file that contains an ejb module that's been deployed to the server/default/deploy folder. I've also deployed another jar (called ptserver.jar) into the server/default/lib folder. The ejb module accesses some of the classes in the ptserver.jar. The ptserver.jar contains some '.properties' files at the top level.

      When a method is invoked in a deployed ejb, it calls down to a class in the ptserver.jar. When a class in ptserver.jar is invoked, it uses getResourceAsStream() to load up a '.properties' file contained in that jar. However, this seems to return null always even if the property file exists in the ptserver.jar. To load the property files, I use <class in ptserver.jar>.getClass().getClassLoader().getResourceAsStream(). I've also used Thread.currentThread().getContextClassLoader(). Doesn't seem to work either.

      What am I doing wrong ? I can't see it. Any help would be appreciated.

      Thanks
      Dinesh

        • 1. Re: getResourceAsStream() from jar in lib folder failing
          raja05

          Im assuming its because all the jars in teh lib directory are loaded by a different class loader than the ones in deploy. So when you call getClass().getClassLoader()....., its the classloader thats used in the deploy directory and not the one in the lib directory.
          For experimenting, can you move the jar file to the deploy directory and see if it looks it up fine?

          -Raj

          • 2. Re: getResourceAsStream() from jar in lib folder failing
            dinesh_soma

            I just tried your suggestion but didn't work either. Kept on getting null as inputstream of getResourceAsStream() method. I basically deployed the 'ear' file and the ptserver.jar to the deploy folder. I hope that's what you meant.

            I believe its not working for the same reason - I'm not getting hold of the classloader that actually loaded the ptserver.jar.

            Dinesh

            • 3. Re: getResourceAsStream() from jar in lib folder failing
              dinesh_soma

              Ok, I've found the problem. The call classLoader.getResource() works fine. It gives me the location of the property file in ptserver.jar. However, it seems that getResourceAsStream() always returns null. I don't quite understand why when getResource() finds it, getResourceAsStream() can't get an input stream to the resource.

              Dinesh