1

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.

jmj
  • 237,923
  • 42
  • 401
  • 438
simran
  • 131
  • 1
  • 1
  • 5
  • You already asked this question, why are you asking it again? http://stackoverflow.com/questions/4561480/how-to-use-jaxb-apis-to-generate-classes-from-xsd – skaffman Dec 30 '10 at 11:53
  • 1
    You only asked it 2 hours ago! Give people a chance. Asking duplicates will only get people irritated. – skaffman Dec 30 '10 at 12:02
  • Google search yielded this question first. Other question asks why NPE, and none of the answers hit on the solution as the answer to this one does. Give the guy a break. – Phil Aug 18 '15 at 02:25

1 Answers1

2

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.

rodion
  • 14,729
  • 3
  • 53
  • 55
  • Nope nothing after adding this too – simran Dec 30 '10 at 14:00
  • make sure you add it before parsing the schema and binding. If still nothing, try `exception.printStackTrace(System.err)`, maybe std-out is getting swallowed for some reason. – rodion Dec 30 '10 at 15:24
  • I must have missed this one -- I've answered the other question ( http://stackoverflow.com/questions/4561480/how-to-use-jaxb-apis-to-generate-classes-from-xsd/4664497#4664497 ). Really, simran, two hours is not really realistic... – JesperSM Jan 12 '11 at 01:17