Error in getResourceAsStream(); Can't read a properties file
kumar30r Jun 17, 2004 4:25 PMI have put a properties file under conf directory 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/process.properties com/../.. (other bean classes)
I am trying to load the file "process.properties" using getClass().getResourceAsStream(name) method.
In this above call if name="conf/process.properties", I get null as the output from "getClass().getResourceAsStream(name)" call.
If name="/conf/process.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 guess, there is something very small that I am missing. Any clues, guys? Thanks a lot.