WSO2类路径 - 它是什么,它在哪里?

时间:2015-05-26 22:01:47

标签: java wso2 wso2carbon wso2as

使用WSO2 AS 5.2.1无法读取类路径中的xml文件。以下是代码和附带的错误:

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

输出是:

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)

无论我在哪里将xml文件填充到WEB-INF / classes或源文件的目录中,它都会在WSO2_HOME(安装目录)中继续查找该文件。非常可怕的情况。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容阅读配置文件

context.getServletContext()的getResource(" /META-INF/holidays.xml")。

感谢。