The solution was to upgrade jaxb to version 2.2.7. I couldn't resolve it in jaxb 1.0.
In fact it was more complicated than that, since there is a bug in the JAXB-RI 2.2.7 which I had to patch. See this question and answer.
Вопрос
I'm seeing an exception, seemingly inside some sun classes, when trying to compile an xml schema.
I've compiled this schema many times before, so I don't suspect the schema of being problematic. I think something may have changed in my java VM, perhaps with the latest upgrade. I have no doubt that upgrading to jaxb 2.0 would fix the problem, since I tried it. However, we have to stick to jaxb 1.0 due to a bug in the JAXB-RI XJC.
Macbook: ant -f build-response.xml Buildfile: /Users/matt/workspace/resources/build-response.xml compilexjc: [echo] Compiling the schema... [xjc] Compiling file:/Users/matt/workspace/schemas/response/partner_response.xsd and others BUILD FAILED /Users/matt/workspace/resources/build-response.xml:34: java.lang.NullPointerException at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.reset(XMLEntityManager.java:1550) at com.sun.org.apache.xerces.internal.parsers.BasicParserConfiguration.reset(BasicParserConfiguration.java:503) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.reset(SchemaParsingConfig.java:541) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:408) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:491) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:510) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1802) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:556) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:523) at com.sun.org.apache.xerces.internal.parsers.XMLGrammarPreparser.preparseGrammar(XMLGrammarPreparser.java:202) at com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.check(SchemaConstraintChecker.java:78) at com.sun.tools.xjc.GrammarLoader.loadXMLSchema(GrammarLoader.java:330) at com.sun.tools.xjc.GrammarLoader.load(GrammarLoader.java:127) at com.sun.tools.xjc.GrammarLoader.load(GrammarLoader.java:76) at com.sun.tools.xjc.XJCTask._doXJC(XJCTask.java:358) at com.sun.tools.xjc.XJCTask.doXJC(XJCTask.java:307) at com.sun.tools.xjc.XJCTask.execute(XJCTask.java:247) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393) at org.apache.tools.ant.Project.executeTarget(Project.java:1364) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1248) at org.apache.tools.ant.Main.runBuild(Main.java:851) at org.apache.tools.ant.Main.startAnt(Main.java:235) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) Total time: 1 second
My build-response.xml file looks like this:
<project name="ERRequest" default="compilexjc" basedir=".">
<target name="init">
<tstamp/>
</target>
<!-- Configure the context path for this application -->
<property name="appname" value="WPI" />
<property name="apppath" value="." />
<property name="path" value="${apppath}"/>
<property name="tmp" value="../tmp_response"/>
<!-- Configure properties to access the Manager application -->
<property file="build.properties"/>
<path id="classpath">
<fileset dir="${LIBS_JARPATH}" includes="*.jar" />
<fileset dir="${JAXB_LIB}" includes="*.jar" />
</path>
<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath refid="classpath" />
</taskdef>
<!--compile Java source files-->
<target name="compilexjc" description="Generate Java source files from XSD">
<mkdir dir="${tmp}"/>
<echo message="Compiling the schema..." />
<xjc target="${tmp}" package="com.mycompany.binding.response"> <!--exception is thrown here-->
<schema dir="../schemas">
<include name="response/response.xsd"/>
<include name="response/partner_response.xsd"/>
</schema>
<produces dir="${tmp}" includes="**/*.java"/>
</xjc>
<copy todir="${tmp}">
<fileset dir="${tmp}">
<include name="**/*.properties"/>
</fileset>
</copy>
</target>
The XJC classes are located in jaxb-xjc.jar which is in the classpath. Here is the meta info for that jar:
Implementation-Version: 1.0.5 Specification-Title: Java Architecture for XML Binding Specification-Version: 1.0
Решение
The solution was to upgrade jaxb to version 2.2.7. I couldn't resolve it in jaxb 1.0.
In fact it was more complicated than that, since there is a bug in the JAXB-RI 2.2.7 which I had to patch. See this question and answer.