I'm trying to read some props from backupData.properties
. It locates in WEB-INF/classes/
. This is how I do:
public class Configures {
private static final String INPUT_FILE = "WEB-INF//classes//backupData.properties";
public static String getMail() {
Properties prop = new Properties();
try {
//load a properties file
prop.load(new FileInputStream(INPUT_FILE));
//get the property value
return prop.getProperty("mail");
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}
}
What INPUT_FILE
should contain? I was trying to put it in src
, like src//backupData.properties
, but it throws FileNotFoundException
. I googled that file should locate in CLASSPATH
(in WEB-INF/classes
as I understood). What is wrong?
PS. I'm using Spring.
This has nothing to do with Spring. If you are deploying a web application, everything in
WEB-INF/classes
will appear starting at the root of the classpath.You can get it the
InputStream
to that resource withSince a web application is not always extracted from its
.war
file, the actual properties file might only exist as a zip entry. As such, you can't (and shouldn't) retrieve it withFileInputStream
.Here's the javadoc.
Since you are using SPRING , I suggest you "CAN" use this as part of your Bean definition:
or
or the plain old as suggested by
@Sotirios Delimanolis