我有一个模块化项目,其中对于每个单个模块,我都使用jaxb2-maven-plugin用xjc编译XSD文件。现在,假设模块以A-> B的顺序编译。对于A来说一切正常(即我得到了* XsdImpl.java),但是对于B我得到了以下内容:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.2:xjc (model) on project B: DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.2:xjc (model) on project B: DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.
at org.codehaus.mojo.jaxb2.XjcMojo.execute(XjcMojo.java:352)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: org.apache.xerces.impl.dv.DVFactoryException: DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.
at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
at org.apache.xerces.impl.dv.DTDDVFactory.getInstance(Unknown Source)
at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.<init>(Unknown Source)
at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.<init>(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.<init>(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.<init>(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.<init>(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.<init>(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.<init>(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaValidatorComponentManager.<init>(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.validation.AbstractXMLSchema.newValidatorHandler(Unknown Source)
at com.sun.tools.xjc.SchemaCache.newValidator(SchemaCache.java:47)
at com.sun.tools.xjc.reader.xmlschema.bindinfo.AnnotationParserFactoryImpl$1$1.startElement(AnnotationParserFactoryImpl.java:136)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:214)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:271)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:97)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:172)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.ModelLoader$SpeculationChecker.startElement(ModelLoader.java:427)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at com.sun.tools.xjc.reader.internalizer.VersionChecker.startElement(VersionChecker.java:78)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)
at com.sun.xml.xsom.parser.JAXPParser.parse(JAXPParser.java:79)
at com.sun.tools.xjc.ModelLoader$2.parse(ModelLoader.java:451)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:237)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:298)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:87)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:147)
at com.sun.tools.xjc.ModelLoader.createXSOMSpeculative(ModelLoader.java:468)
at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:338)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:145)
at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:91)
at com.sun.tools.xjc.Driver.run(Driver.java:287)
at org.codehaus.mojo.jaxb2.XjcMojo.execute(XjcMojo.java:301)
... 21 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
这两个模块对插件使用相同的配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>model</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<clearOutputDir>false</clearOutputDir>
<bindingDirectory>${basedir}/src/main/resources/xsd</bindingDirectory>
<outputDirectory>${basedir}/src/main/generated</outputDirectory>
<schemaDirectory>${basedir}/src/main/generated/xsd</schemaDirectory>
<schemaFiles>base.xsd</schemaFiles>
<staleFile>${project.build.directory}/generated-sources/jaxb/.staleFlag-model</staleFile>
</configuration>
</execution>
</executions>
</plugin>
该错误总是出现在第二个模块上(无论是A还是B)。
我花了很多时间试图找出幕后发生的事情,但不幸的是没有成功...
例如,我想了解在这里第一次执行时会发生什么:
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
--->>> at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)
我猜想使用了另一个类来代替org.apache.xerces.jaxp.SAXParserImpl,但是以某种方式第二次选择了org.apache.xerces.jaxp.SAXParserImpl。您知道如何证明这一点吗?还是有人遇到过同样的问题?
在此先非常感谢您的任何提示/帮助!
再见
最佳答案
问题是您无意中提供了没有JAXP API的JAXP实现,该实现与JRE捆绑的JAXP API不兼容。
为了解决此问题,我向项目中的所有jaxb2插件添加了JAXP API +实现依赖项:
</executions>
<dependencies>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</plugin>
记住要更新所有的jaxb2插件,而不仅仅是失败的插件。这是因为插件依赖项在第一次执行时仅被解析一次。这可能是发生故障的模块,也可能不是。
==编辑==
请记住,从Java 1.6开始,所有必需的JAXP,JAXB,xerces,xalan,JAX-WS RI,SAAJ和相关类都捆绑在JRE库中。
除非您使用过时的JDK(1.5或更早版本)进行构建,否则您无需在项目中包含任何这些dep。
因此,如果您从POM中删除JAXB依赖项(并可能升级到最新的jaxb2-maven-plugin),则您的构建可能会正常工作。