【发布时间】:2013-11-20 02:07:56
【问题描述】:
我在 RESTEasy Web 服务上运行了以下 Java 代码,以获取用于验证 xml 的架构文件(注意:项目文件夹名为“MyWebService”):
String classDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
String myWebServiceDir = classDir.substring(0, classDir.lastIndexOf("MyWebService"));
String instanceXSDPath = myWebServiceDir + SCHEMAS_FOLDER + xsdFile;
System.out.println("Streamsource file location: " + instanceXSDPath);
File file = new File(instanceXSDPath);
//StreamSource streamSource = new StreamSource(file);
// Note: Using StreamSource or File seems to make no difference to the issue
Schema schema = factory.newSchema(file);
当我在本地机器上运行上述代码时,一切正常。但是,当我在我的开发服务器上运行上述代码时,我收到以下错误:
2013-11-20 12:47:48,275 信息 [标准输出] (ajp-127.0.0.1-8009-4) 流源文件位置: 文件:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd 2013-11-20 12:47:48,275 错误 [com.mywebservice.dao.validate] (ajp-127.0.0.1-8009-4) 无法解析给定对象的模式 验证:org.xml.sax.SAXParseException:schema_reference.4:失败 阅读架构文档 'file:/Y:/jboss/jboss-as/bin/file:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd', 因为 1) 找不到文件; 2) 文件不能 读; 3) 文档的根元素不是 .在 org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(未知 来源)
我不明白为什么在服务器 EAP 日志中,上面的代码试图从如下所示的路径中读取 instance.xsd:
'file:/Y:/jboss/jboss-as/bin/file:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd'
...因为在我的 localhost EAP 日志中,它正在从如下所示的位置读取 instance.xsd:
'位置: /C:/Users/chen/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1382499548190/deploy/Schemas/Extensions/1/instance.xsd'
有人知道为什么吗?为什么打印消息在服务器上显示“文件”,但在我的 locahost 上分别显示在每个服务器日志中的“位置”?也许这与问题有关。
【问题讨论】:
标签: java xml eclipse jboss xsd