I have deployed my java web service successfully using tomcat. This web service is accessing a configuration file (.Properties) I have placed the config.properties files in the following directory
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ProcurementWS1\WEB-INF\classes\MainPackagePr
ProcurmentWS1 is the name of the WAR file
this is how am trying to access it from my code:
Properties properties = new Properties();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("procwsconfig.properties");
properties.load(is);
And am getting a null pointer exception on load
can you tell me what am doing wrong?
put it in src/config direct to config package in source , upon build it will go to /WEB-INF/classes/config/config.properties
and this.getClass().getResourceAsStream("/config/config.properties");
and then I created a Service Class in the same project which has a method.
public static InputStream getConfigAsInputStream(){
return Service.class.getResourceAsStream("/config/config.properties");
}
you can place it in somewhere on your class path and under any folder of your .java source files using :
ResourceBundle bundle1 = ResourceBundle.getBundle("com.witness.web.license.l10n.VersionsFileName");
String fileName = bundle1.getString("11.1");
com.witness.web.license.l10n
being your package
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.