我正在编写一个类来在 java 中运行 xjc。我的代码如下:
SchemaCompiler sc = XJC.createSchemaCompiler();
URL url = new URL("file://E:\\JAXB\\books.xsd");
sc.parseSchema(new InputSource(url.toExternalForm()));
S2JJAXBModel model = sc.bind();
JCodeModel cm = model.generateCode(null, null);
cm.build(new FileCodeWriter(new File("E:\\JAXBTest")));
当我运行这个时,我得到的模型为空。
任何人都可以帮助我或提供任何我可以了解这一点的链接。
最佳答案
如果您查看 SchemaCompiler
API 中的 bind()
方法,它会显示:
bind() returns null if the compilation fails. The errors should have been delivered to the registered error handler in such a case.
因此,您需要使用 SchemaCompiler.setErrorListener()
注册一个错误监听器,如下所示:
sc.setErrorListener(new ErrorListener(){
public void error(SAXParseException exception){
exception.printStackTrace();
}
});
希望您能获得有关问题所在的更多信息。
关于java - SchemaCompiler bind() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4562324/