SchemaCompiler bind() 返回 null

发布于 2024-10-10 04:50:22 字数 417 浏览 0 评论 0原文

我正在编写一个类来在 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")));

当我运行它时,我得到的模型为空。

任何人都可以帮助我或提供任何我可以知道这一点的链接。

I' m writing a class to run xjc in java. my code goes as follows:

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")));

i get model as null when i run this.

Can anyone pls help me or provide any link where i can know abt this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2024-10-17 04:50:22

如果您查看 SchemaCompiler API 中的 bind() 方法,它会显示:

如果编译,bind() 返回 null
失败了。错误应该是
传递到注册的错误
在这种情况下的处理程序。

因此,您需要使用 SchemaCompiler.setErrorListener() 注册一个错误侦听器,如下所示:

sc.setErrorListener(new ErrorListener(){
  public void error(SAXParseException exception){
    exception.printStackTrace();
  }
});

希望您能获得有关出现问题的更多信息。

If you look in the SchemaCompiler API for bind() method it says:

bind() returns null if the compilation
fails. The errors should have been
delivered to the registered error
handler in such a case.

So, you need to register an error listener using SchemaCompiler.setErrorListener() with something like this:

sc.setErrorListener(new ErrorListener(){
  public void error(SAXParseException exception){
    exception.printStackTrace();
  }
});

And hopefully you will get more information on what is going wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文