How to use a .properties file in Eclipse Java Dynamic Web Project?

What you did is correct, ie right clicking the project and new--file.You have to Put your properties where you start your jvm from. Please look into the attached image. The properties file is marked in red. Look if your properties file is also located something like this. Also add this in your code to find out where to put your file:

System.out.println(new File(".").getAbsolutePath());

For more details please follow this link- FileNotFoundException when using java properties file

enter image description here


You should instead be using the more portable java.util.Properties#load(InputStream) with the result of javax.servlet.ServletContext#getResourceAsStream(String).


Normally, you make sure the properties file is in the project runtime classpath (e.g. WEB-INF/classes) and then load it using either the System classloader or the property file handler's classloader, i.e. (Freehand typing from memory -- NOT COMPILED)

try{
     Properties p = new Properties();
     InputStream in = MyPropertyHandler.getClass()
           .getClassLoader()
           .getResourceAsStream("com/package/props/database.properties");
     p.load(in);
catch(IOException e){
     e.printStackTrace(System.err);
}

I'm betting you aren't pointing at the correct location. Make sure you're properties file is in the correct place. Using that code, I believe it is looking for ${CURRENT_WORKING_DIR}/database.properties, which is the case of a web app in eclipse is WEB-INF/classes (i think).