Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从项目文件夹xsd中读取xsd文件_Java_Xml_Jaxb - Fatal编程技术网

Java 无法从项目文件夹xsd中读取xsd文件

Java 无法从项目文件夹xsd中读取xsd文件,java,xml,jaxb,Java,Xml,Jaxb,我正在尝试验证WEB-INF中xsd文件夹下项目中的xsd。 请找到我开发的代码 JAXBContext jc = JAXBContext.newInstance(OTAHotelResRQ.class); JAXBSource source = new JAXBSource(jc, reqJAXB); SchemaFactory sf =SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schem

我正在尝试验证WEB-INF中xsd文件夹下项目中的xsd。 请找到我开发的代码

JAXBContext jc = JAXBContext.newInstance(OTAHotelResRQ.class);

JAXBSource source = new JAXBSource(jc, reqJAXB);

SchemaFactory sf =SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 

Schema schema = sf.newSchema(new File("XSD/OTA_HotelResRQ.xsd"));

Validator validator = schema.newValidator();

validator.validate(source);
但我无法从XSD中读取它。它显示以下异常

java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: schema_reference.4: Failed to read schema document 'file:///D:/hayyat/softwares/jboss-4.2.3.GA/bin/XSD/OTA_HotelResRQ.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:322)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
java.lang.RuntimeException:org.apache.cxf.interceptor.Fault:schema_reference.4:读取架构文档失败'file:///D:/hayyat/softwares/jboss-4.2.3.GA/bin/XSD/OTA_HotelResRQ.XSD',因为1)找不到文档;2) 文件无法读取;3) 文档的根元素不是。
位于org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
位于org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:322)
位于org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
位于org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
位于org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
位于org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
所以请解决我的问题

问候 Narsi将XSD放在类路径中(WEB-INF/classes或jar放在库中),并从类路径读取