使用 Ant 的 xjc2 任务绑定一些有效的 XML 文档时,我收到以下失败消息:
[xjc2] [ERROR] null
[xjc2] unknown location
文件与其他绑定成功的文件非常相似,所有导入的模式都存在。以详细模式运行 xjc 产生:
Parent is not Defined Class...I cannot get the fields from this class
有人知道这意味着什么吗?
模式正确性检查
在我们使用 XJC 的过程中,我们看到了一个类似的问题(参见下面的链接),该问题通过禁用模式正确性检查来解决:
尝试以下系统属性来禁用架构正确性检查。
-Dcom.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.noCorrectnessCheck=true
对于 Ant,请尝试:
<xjc target="src">
<schema dir="src" includes="**/*.xsd" excludes="**/debug.xsd"/>
<arg value="-nv" />
</xjc>
从以下页面中,-nv 参数与架构正确性检查有关:
进入代码
您可以尝试以编程方式与 XJC 交互(见下文)并插入您自己的 EntityResolver 以查看导入/包含失败的位置:
import com.sun.codemodel.*;
import com.sun.tools.xjc.*;
import com.sun.tools.xjc.api.*;
SchemaCompiler sc = XJC.createSchemaCompiler();
sc.setEntityResolver(new YourEntityResolver());
sc.setErrorListener(new YourErrorListener());
sc.parseSchema(SYSTEM_ID, element);
S2JJAXBModel model = sc.bind();