在尝试编译xml架构时,我看到一个异常,似乎在某些sun类中。
之前我已多次编译此架构,所以我不怀疑架构存在问题。我认为我的java VM中可能有一些变化,可能是最新的升级。我毫不怀疑升级到jaxb 2.0会解决这个问题,因为我试过了。但是,由于bug in the JAXB-RI XJC,我们必须坚持使用jaxb 1.0。
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
我的build-response.xml文件如下所示:
<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>
XJC类位于类路径中的jaxb-xjc.jar中。以下是该jar的元信息:
Implementation-Version: 1.0.5 Specification-Title: Java Architecture for XML Binding Specification-Version: 1.0
答案 0 :(得分:0)
解决方案是将jaxb升级到2.2.7版。我无法在jaxb 1.0中解决它。
实际上它比这更复杂,因为JAXB-RI 2.2.7中存在一个我必须修补的错误。见this question and answer.