Question

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?

Was it helpful?

Solution

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");

enter image description here

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");
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top