gpt4 book ai didi

java - 无法从项目文件夹 xsd 读取 xsd 文件

转载 作者:行者123 更新时间:2023-11-30 04:41:55 25 4
gpt4 key购买 nike

我正在尝试验证 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)

所以请解决我的问题。

问候纳尔西

最佳答案

将 XSD 放入类路径中(WEB-INF/classes 或 lib 中的 jar)并从类路径中读取。

How to read properties file in web application?

Getting the inputstream from a classpath resource (XML file)

关于java - 无法从项目文件夹 xsd 读取 xsd 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12075275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com