我有一个模块化项目,在每个模块中,我使用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。你知道我怎么能证明这一点?或者是否有人遇到过同样的问题?
非常感谢任何提示/帮助! 再见
答案 0 :(得分:9)
问题是您在没有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库中。
您不需要在项目中包含任何这些deps,除非您使用古老的JDK(1.5或更早版本)构建。
因此,如果从POM中删除JAXB依赖项(并且可能升级到最新的jaxb2-maven-plugin),那么您的构建可能会正常工作。
答案 1 :(得分:1)
我有类似的问题,并通过将Maven编译器的版本号从1.9更改为3.1为我工作。在我的POM中,我在插件下的2个位置进行了此更改...
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
答案 2 :(得分:1)
在我的应用程序中包含一个旧的jar时遇到了类似的问题。在我的pom文件中,我使用了排除项来解决问题。
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>