Using WSO2 AS 5.2.1 been unable to read a xml file in the classpath. Here is the code and the accompanying error:
try {
InputStreamReader inputReader =new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(xmlFile.getName()));
HolidayInitializer holidayInit = new HolidayInitializer();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = factory.createXMLStreamReader(inputReader);
institutionVumcHolidays = holidayInit.processHolidays(xmlStreamReader);
log.info(getClass().getSimpleName() + " loadHolidays() Found Holidays config file in classpath");
} catch (Exception e) {
log.error(getClass().getSimpleName() + " loadHolidays() Holidays config file does not exist in classpath", e);
}
And the output is:
2015-05-26 02:49:14 ERROR ExternalCallbackWebServiceImpl:343 - ExternalCallbackWebServiceImpl loadHolidays() Holidays config file does not exist in classpath
java.io.FileNotFoundException: c:\wso2as-5.2.1\Holidays.xml (No such file or directory)
at java.io.FileInputStream.open(Native Method)
No matter where I stuff the xml file in WEB-INF/classes or in the directory of the source file, it keeps looking for that file in WSO2_HOME (installation directory). Very dire situation. Would appreciate your help.
You can read the config file with the following,
context.getServletContext().getResource("/META-INF/holidays.xml")
thanks.