mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
106 stars 77 forks source link

Plugin cannot find XSD's imported via <xsd:import> #106

Open RohanRathod2009 opened 6 years ago

RohanRathod2009 commented 6 years ago

Hi Team,

Recently i was trying to upgrade jaxb2-maven-plugin from 1.3 to 2.3.1. While upgrading this plugin my "xjc" goal is failing for XSD's importing other XSD's.

Below is the skeleton of my project: common-model -----------------common-modelA -------------------------------------------schema/A.xsd -------------------------------------------pom.xml
  -----------------common-modelB
  -------------------------------------------schema/B.xsd        // This imports A.xsd
  -------------------------------------------pom.xml

common-dal common-service

Now, the "xjc" goal for B.xsd is failing , its unable to find the location of A.xsd.

This issue we are facing after upgrading to 2.x. It works till 1.6. Is this an issue with 2.2 and later versions of the plugin?

Below is the snippet of my plugin usage.

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.3.1</version>
                <dependencies>
                    <dependency>
                        <!-- toString() generation dependency -->
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.5</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>default-xjc</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                            <extension>true</extension>
                            <enableIntrospection>true</enableIntrospection>
                            <generateEpisode>true</generateEpisode>
                            <xjcArgs>
                            </xjcArgs>
                            <sources>
                                <source>${project.build.directory}/schema</source>
                            </sources>
                            <xjbSources>
                            <xjbSource>${project.build.directory}/bindings</xjbSource>
                            </xjbSources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
lennartj commented 6 years ago

The semantics are slightly different in the 2.x JAXB version. Use relative path to the file where the XSD was included:

    <!--
        Change since version 2.0 of the j-m-p:

        Note that the schemaLocation path must point to the XSD file
        relative to *this* file, rather than the basedir.
    -->
  <jxb:bindings schemaLocation="../xsd/address.xsd" node="//xsd:schema">
      <jxb:schemaBindings>
         <jxb:package name="com.example.myschema"/>
      </jxb:schemaBindings>
  </jxb:bindings>