Search This Blog

Friday, September 11, 2015

Read properties File from a WAR module running on Eclipse

I came across a problem where I was able to read property file for a Java project but when it was being deployed to tomcat as a war it was giving problem.

 
The code that worked is pasted below

 
  1. Create a src folder and name it resources
  2. Put the property file there.
  3. In the code access it like this

 

 
 InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("db.txt");




If you are making it for a DBconnection class which you are using for DAO in your code. The DBconnection  class will be static.

No comments:

Post a Comment