Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxb2 maven plugin does not work upon second execution

I have a modular project in which, for every single module, I use jaxb2-maven-plugin to compile XSD files with xjc. Now, suppose the modules are compiled in the order A-->B. For A everything works fine (i.e. I get the *XsdImpl.java), but for B I get the following:

[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

Both the modules use the same configuration for the plugin:

<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>

The error comes always for the second module (it doesn't matter whether A or B). I've spent a lot of time trying to figure out what happens behind the scenes but unfortunately without success... For example, I would like to understand what happens upon the first execution here:

    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
   --->>> at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)

I would guess another class is used instead of org.apache.xerces.jaxp.SAXParserImpl, but somehow org.apache.xerces.jaxp.SAXParserImpl is selected the 2nd time.. Do you know how could I proof this? Or did anybody experience the same issue already?

Thanks in advance a lot for any hint/help! Bye

like image 670
Federico Avatar asked Dec 21 '22 04:12

Federico


2 Answers

The issue is that you have inadvertently provided a JAXP implementation without the JAXP API, that is incompatible with the JAXP API that is bundled with the JRE.

To solve this issue, I added JAXP API + implementation dependencies to all jaxb2 plugins in my project:

            </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>

Remember to update all jaxb2 plugins, not just the failing one. This is because plugin dependencies are resolved only once when the plugin is executed for the first time. This may or may not be the module where the failure occurs.

== EDIT ==

Keep in mind that since Java 1.6, all the necessary JAXP, JAXB, xerces, xalan, JAX-WS RI, SAAJ and related classes are bundled in the JRE library.

You do not need to include any of these deps in your project, unless you're building with an archaic JDK (1.5 or older).

So, if you remove JAXB dependencies from your POM (and maybe upgrade to the latest jaxb2-maven-plugin), your build will probably work fine.

like image 86
rustyx Avatar answered Dec 28 '22 13:12

rustyx


I had the similar issue and by changing version number for below Maven compiler from 1.9 to 3.1 worked for me. In my POM i had made this change at 2 places under plugins...

<artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
like image 30
Akshay Avatar answered Dec 28 '22 11:12

Akshay