- This topic has 5 replies, 2 voices, and was last updated 18 years, 8 months ago by Riyad Kalla.
-
AuthorPosts
-
senthilkumartnrMemberHi,
I have the properties file under the WEB-INF folder. When I do the Remote Debuging from Myeclipse I am getting Property File not found in Classpath error. I have installed the application as packaged war file.
I am getting the home page also is recognize the realm from the server.
But when I try to connect to the Database through code its not recognizing the property file under the WEB-INF folder.
Here is my code to read the property file.
propsFileStream = java.lang.Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(“DB.properties”);Where should I put the properties file to be picked by the class files ?
Thanks for the help.
Riyad KallaMemberThe properties file should go into your source tree, preferablly in the same package as your DB classes so you can simply have your DB class do a getResourceAsStream to load the file.
You could also place it in the root of your source tree and load it with “/DB.properties” as the path, but I usually prefer putting it with the class that needs it.
senthilkumartnrMemberRiyad Thanks for the prompt reply.
I treied the Property Files in the source Tree and mentioned them as /DB.Properties. Still its not working.
Also copied the properties in the package folder , still I am getting the same error.
Do I miss anything ?
Thanks for the propmt help.
Riyad KallaMemberPaste your code you are using to load the properties file, maybe you are doing something wrong there.
senthilkumartnrMemberNow I am getting the property file loaded properly. But I had to install the application as exploded archive. If I install the application as Packaged Archive its not getting loaded.
Here is the code.
try {
props = new Properties();//System.err.print(“loadProperties getResourceAsStream stg.properties…”);
// find stg.properties from the classpath
java.io.InputStream propsFileStream = lock.getClass()
.getResourceAsStream(“/DB.properties”);
System.out.println(“stg.properties=”+propsFileStream);
//System.err.println(“done”);
// here’s an ugly hack to get it working in WebLogic
if (propsFileStream == null) {
//System.err.print(“loadProperties trying getContextClassLoader.getResourceAsStream( stg.properties)…”);
propsFileStream = java.lang.Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(“/DB.properties”);
System.out.println(“stg.properties=”+propsFileStream);
}//System.err.println(“done”);
// if we haven’t found it now, report failure
if (propsFileStream != null) {
//System.err.print(“loadProperties props.load…”);
props.load(propsFileStream);//System.err.println(“done”);
} else {
props = null;
throw new PropertiesException(
“Properties file stg.properties not found in classpath”);
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
Riyad KallaMemberGood for “loading resource from JAR”. IIRC getResourceAsStream should work but it seems to be not working when the resource is inside of a JAR, so google for some code snippets that do that.
-
AuthorPosts