-
1. Re: How to access property files
jaikiran Nov 20, 2006 2:32 AM (in response to prakashg)When you say, you had placed the properties file in your classpath, where exactly had you placed that? Also how are you trying to access the file in your code? Please post the code.
-
2. Re: How to access property files
prakashg Nov 20, 2006 2:38 AM (in response to prakashg)private static LoadConfig loadConfig = new LoadConfig();
private Class ldClass = null;
private final String PROP_FILE_NAME = "config.properties";
private Properties prop = new Properties();
private LoadConfig()
{
try {
prop.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream(PROP_FILE_NAME));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getFilePath()
{
return this.prop.getProperty("XML_PATH");
}
public String getResultPath()
{
return this.prop.getProperty("RESULT_PATH");
}
public static LoadConfig getConfig(){
return loadConfig;
}
This is the code , I added the property file to the class path by editing configure buil path tab in eclipse, thanks for your reply -
3. Re: How to access property files
jaikiran Nov 20, 2006 2:45 AM (in response to prakashg)prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PROP_FILE_NAME));
I usually do it this way, whenever i am loading a properties file:
prop.load(this.getClass().getClassLoader().getResourceAsStream(PROP_FILE_NAME));
Assuming that the PROP_FILE_NAME is just the name of the file and not the path, then that file should be present directly inside the war/ear/jar. If the PROP_FILE_NAME is something like "/conf/myprops/someprop.properties" then this is how the directory structure will look like:myApp.war | |------------ META-INF | | |------------- conf | |------ myprops | |------------ someprop.properties | |------------- WEB-INF | |--------- classes
-
4. Re: How to access property files
prakashg Nov 21, 2006 3:52 AM (in response to prakashg)Thanks a lot now the property file gets loaded ....