Reputation: 494
I have a config file containing server information such as FTP URL's and their credentials. I am trying to, on deployment of my web app, reference the config.properties file to assign the stored values to local variables but for whatever reason cannot find the file.
I have a getConfigProperties class:
public class getConfigProperties {
public Properties getConfig(String fileName) {
// load config file
Properties prop = new Properties();
InputStream input = null;
try {
// grab config file from destination
input = getConfigProperties.class.getClass().getResourceAsStream(
fileName);
// check if input is null
if (input == null) {
System.out.println("Sorry, unable to find "
+ "config.properties");
return null;
}
// load content
prop.load(input);
// start to declare variables
// Prod vars
System.out.println(prop.getProperty("prismUrlProd"));
System.out.println(prop.getProperty("prismUserProd"));
System.out.println(prop.getProperty("prismPassProd"));
System.out.println(prop.getProperty("cardUrlProd"));
System.out.println(prop.getProperty("cardUserProd"));
System.out.println(prop.getProperty("cardPassProd"));
System.out.println(prop.getProperty("pwcProd"));
System.out.println(prop.getProperty("esdSignInProd"));
System.out.println(prop.getProperty("emailProd"));
// used to catch possible errors
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return prop;
}
public static void main(String[] args) {
getConfigProperties a = new getConfigProperties();
a.getConfig("/config/config.properties");
}
}
And I use this in another class to assign the variables. Inside my method, I set a Properties object to what is returned from getConfig(String filename):
public static void initialize() {
// load config file
getConfigProperties config = new getConfigProperties();
Properties prop = config.getConfig("/config/config.properties");
}
It's explained in properties file in web app that on deplyoment, our location of the config.properties changes, but when trying "/WEB-INF/classes/config/config.properties", I can't find the file. Using the main in my getConfigProperties class, I am able to find config.properties no problem and reference the text in my config file by printing it to console. Any possible suggestions as to where this file may be on deployment? Do I have to reference it a certain way? Any help would much be appreciated.
Upvotes: 0
Views: 1176
Reputation: 494
I got this to work by putting config.properties in my src folder and referencing it by "config.properties".
Upvotes: 0