谁能帮忙
我在名为 GML-XSD 的目录中有一个 XSD 文件,并使用 Netbeans 8.0.2,在源代码中我使用了该文件的字符串
String gmlXSDFile = "etc/GML_XSD/epsg/EPSG.xsd";
目录为project/GML-XSD/epsg/EPSG.xsd 问题是当我构建项目并在 Glassfish Server 或 Jetty 上运行它时,它提示找不到 etc 文件夹。我怎样才能解决这个问题,以确保它会尝试在 war 文件中找到“etc/GML_XSD”,而不是部署它的目录。
谢谢。
Failed to read schema document 'file:/usr/local/ras/log/etc/GML_XSD/epsg/EPSG.xsd', because 1) could not find the document
编辑:读取此文件的代码(不起作用)
Source[] sources = new StreamSource[1];
sources[0] = new StreamSource(new File(gmlXSDFile));
编辑:图像内的新代码
String gmlXSDFile = "/GML/epsg/EPSG.xsd";
可以支持正确读取EPSG.xsd文件,但无法导入属于以下其他包的其他xsd文件:
<import namespace="http://www.opengis.net/gml/3.2" schemaLocation="../gml/3.2.1/gml-3.2.1.xsd"/>
无法将名称“gml:Definition”解析为“元素声明”组件
最佳答案
尝试了很多方法都行不通,最终我成功了
URL schemaURL = Thread.currentThread().getContextClassLoader().getResource("GML/epsg/EPSG.xsd");
Schema schema = factory.newSchema(schemaURL);
并且不需要创建任何无济于事的包或资源包。我现在很高兴。
关于Java SAXParser 无法读取资源目录中导入的 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34059497/