SAXReader reader = new SAXReader();
///////////////////////////////////
//获取类加载路径,项目中则为bin目录,打成jar包后,则是jar包所在的目录
String schemaPath = Thread.currentThread().getContextClassLoader().getResource("ImportDatas.xsd").getPath();
log.info("schema路径为:" + schemaPath);
try {
reader.setValidation(false);
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", null);
reader.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
schemaPath
);
} catch (Exception e) {
log.debug("设置schema校验失败:" + e.getMessage());
throw e;
}
return reader;
}以上代码在eclipse里运行正常,可当打包成jar包后运行,则出现如下异常:
Exception in thread "main" java.lang.Exception: cvc-elt.1: Cannot find the declaration of element 'importDatas'.打印schema路径为:file:/D:/workspace/ygnbi_2.0_plugin_guowang_shandong/core_lib/ygnbi.initializer.jar!/ImportDatas.xsd请问如何用dom4j读取jar包里的xsd校验xml?
///////////////////////////////////
//获取类加载路径,项目中则为bin目录,打成jar包后,则是jar包所在的目录
String schemaPath = Thread.currentThread().getContextClassLoader().getResource("ImportDatas.xsd").getPath();
log.info("schema路径为:" + schemaPath);
try {
reader.setValidation(false);
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", null);
reader.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
schemaPath
);
} catch (Exception e) {
log.debug("设置schema校验失败:" + e.getMessage());
throw e;
}
return reader;
}以上代码在eclipse里运行正常,可当打包成jar包后运行,则出现如下异常:
Exception in thread "main" java.lang.Exception: cvc-elt.1: Cannot find the declaration of element 'importDatas'.打印schema路径为:file:/D:/workspace/ygnbi_2.0_plugin_guowang_shandong/core_lib/ygnbi.initializer.jar!/ImportDatas.xsd请问如何用dom4j读取jar包里的xsd校验xml?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货