2 Replies Latest reply on Jun 18, 2004 11:57 AM by kumar30r

    Error in getResourceAsStream; How to read a resource from a

    kumar30r

      I am using JBoss 3.2.3. I have put a properties file with in a JAR.
      I am not able to read its contents from one of the beans deployed through the same JAR file.

      Contents of the JAR:
      meta-inf/jboss.xml
      meta-inf/ejb-jar.xml
      conf/Ebonding.properties
      com/../.. (other bean classes)



      I am trying to load the file "Ebonding.properties" using getClass().getResourceAsStream(name) method.

      In this above call if name="conf/Ebonding.properties", I get null as the output from "getClass().getResourceAsStream(name)" call.

      If name="/conf/Ebonding.properties" (with a / in front), then "getClass().getResourceAsStream(name)" method seem to return a valid stream but when I use this stream to load a Properties object, it gives me the following error (showing the top portion of a huge stack Trace)

      2004-06-17 15:58:08,325 ERROR [STDERR] java.lang.NullPointerException: name
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.util.zip.ZipFile.getEntry(ZipFile.java:141)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.util.jar.JarFile.getEntry(JarFile.java:194)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.util.jar.JarFile.getJarEntry(JarFile.java:181)
      2004-06-17 15:58:08,335 ERROR [STDERR] at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:668)
      2004-06-17 15:58:08,335 ERROR [STDERR] at sun.misc.URLClassPath.getResource(URLClassPath.java:157)
      2004-06-17 15:58:08,335 ERROR [STDERR] at sun.misc.URLClassPath.getResource(URLClassPath.java:209)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getBootstrapResource(ClassLoader.java:923)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getResource(ClassLoader.java:784)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getResource(ClassLoader.java:782)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getResource(ClassLoader.java:782)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getResource(ClassLoader.java:782)
      2004-06-17 15:58:08,335 ERROR [STDERR] at org.jboss.mx.loading.UnifiedClassLoader.getResourceLocally(UnifiedClassLoader.java:308)
      2004-06-17 15:58:08,335 ERROR [STDERR] at org.jboss.mx.loading.UnifiedLoaderRepository3.getResourceFromClassLoader(UnifiedLoaderRepository3.java:360)
      2004-06-17 15:58:08,335 ERROR [STDERR] at org.jboss.mx.loading.UnifiedLoaderRepository3.getResource(UnifiedLoaderRepository3.java:270)
      2004-06-17 15:58:08,335 ERROR [STDERR] at org.jboss.mx.loading.UnifiedClassLoader3.getResource(UnifiedClassLoader3.java:223)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:969)
      2004-06-17 15:58:08,335 ERROR [STDERR] at java.lang.Class.getResourceAsStream(Class.java:1323)
      2004-06-17 15:58:08,335 ERROR [STDERR] at com.test.ebonding.data.EbondingProperties.<init>(EbondingProperties.java:59)
      2004-06-17 15:58:08,335 ERROR [STDERR] at com.test.ebonding.data.EbondingProperties.<clinit>(EbondingProperties.java:27)


      Code Snippet (in the Constructor of com.test.ebonding.data.EbondingProperties class):

      Properties systemProp = new Properties();
      InputStream propFileStream = getClass().getResourceAsStream("conf/Ebonding.properties");
      systemProp.load(propFileStream);


      I am clueless and spent lot of time trying to put this properties under different directories within the JAR. No Success. Also read about "meta class path" in the MANIFEST file in some forum thread, but now sure what I should set it to.

      I tried putting this properties file in all kinds of directories with the Jboss installation and was hoping the ClassLoader would find this resource. No success either.

      I even tried putting this file in some other directory outside Jboss installation (and not within JAR), but could not access it even though I gave the absolute path with the protocol as "file:" in the filename. I get a "FileNotFoundException" when I use the "FileInputStream".

      Any clues, guys? Is there a bug in Jboss 3.2.3 or am I missing something?

      Thanks a lot.