Jaxb, xsd import not recognized

I have a big problem with the jaxb plugin. I have project A where I have a src / main / resources / xsd / common.xsd file. In this project, I am using the cxf-xjc-plugin to create Java classes. I also have an episode file at src / main / resources / META-INF called sun-jaxb.episode

Then I have project B that has maven dependency to project A. In this project I have src / main / resources / catalog.txt

PUBLIC "http://www.some_path" "maven:GROUP_ID_OF_PROJECT_A:ARTIFACT_ID_OF_PROJECT_A:jar::!/common.xsd"

      

In project B, I have a pom file with jaxb plugin

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <configuration>
                <extension>true</extension>
                <episodes>
                    <episode>
                        <groupId>GROUP_ID_OF_PROJECT_A</groupId>
                        <artifactId>ARTIFACT_ID_OF_PROJECT_A</artifactId>
                    </episode>
                </episodes>
                <catalogs>
                    <catalog>src/main/resources/catalog.txt</catalog>
                </catalogs>
            </configuration>
 </plugin>

      

Next, I have project B

 src/main/resources/other/xsd my main.xsd 

      

where i am using the type definitions from common.xsd

I have xmlns: cmns = "http: //www.some_path" // this is the same as in catalog.txt and

<xs:import namespace="http://www.some_path"/> 

      

but the problem is i am getting undefined error of simple or complex type because it does not recognize cmns

+2


source to share


1 answer


I am using this plugin to solve public xsd import

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.1</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <args>
            <arg>-Xannotate</arg>
            <arg>-Xnamespace-prefix</arg>
            <arg>-nv</arg>
        </args>
        <extension>true</extension>
        <forceRegenerate>true</forceRegenerate>
        <bindingDirectory>${basedir}/src/main/resources/xjb</bindingDirectory>
        <bindingIncludes>
            <include>*.xjb</include>
        </bindingIncludes>
        <schemas>
            <schema>
                <fileset>
                    <directory>${basedir}/src/main/resources/xsd</directory>
                    <includes>
                        <include>*.xsd</include>
                    </includes>
                </fileset>
            </schema>
            <schema>
                <dependencyResource>
                    <groupId>groupID</groupId>
                    <artifactId>artifactID</artifactId>
                    <resource>target.xsd</resource>
                </dependencyResource>
            </schema>

        </schemas>
        <episodes>
            <episode>
                <groupId>groupID</groupId>
                <artifactId>artifactID</artifactId>
            </episode>
        </episodes>
        <debug>true</debug>
        <verbose>true</verbose>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics</artifactId>
                <version>0.6.2</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics-annotate</artifactId>
                <version>0.6.2</version>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-namespace-prefix</artifactId>
                <version>1.1</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

      


Plugin for pom.xml project A

<plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <args>
                <arg>-Xannotate</arg>
                <arg>-nv</arg>
                <arg>-Xnamespace-prefix</arg>
            </args>
            <extension>true</extension>
            <schemas>
                <schema>
                    <fileset>
                        <directory>${basedir}/src/main/resources/xsd/</directory>
                        <includes>
                            <include>A.xsd</include>
                        </includes>
                    </fileset>
                </schema>
            </schemas>
            <bindingDirectory>src/main/resources/xjb</bindingDirectory>
            <bindingIncludes>
                <include>*.xjb</include>
            </bindingIncludes>
            <debug>true</debug>
            <verbose>true</verbose>
            <forceRegenerate>true</forceRegenerate>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.0</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-annotate</artifactId>
                    <version>0.6.0</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-namespace-prefix</artifactId>
                    <version>1.1</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>

      

Plugin for pom.xml of project B



<plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <args>
                <arg>-Xannotate</arg>
                <arg>-Xnamespace-prefix</arg>
                <arg>-nv</arg>
            </args>
            <extension>true</extension>
            <forceRegenerate>true</forceRegenerate>
            <bindingDirectory>${basedir}/src/main/resources/xjb</bindingDirectory>
            <bindingIncludes>
                <include>*.xjb</include>
            </bindingIncludes>
            <schemas>
                <schema>
                    <fileset>
                        <directory>${basedir}/src/main/resources/xsd/</directory>
                        <includes>
                            <include>B.xsd</include>
                        </includes>
                    </fileset>
                </schema>
                <schema>
                    <dependencyResource>
                        <groupId>AgroupID</groupId>
                        <artifactId>AartifactID</artifactId>
                        <resource>xsd/A.xsd</resource>
                    </dependencyResource>
                </schema>
            </schemas>
            <episodes>
                <episode>
                    <groupId>AgroupID</groupId>
                    <artifactId>AartifactID</artifactId>
                </episode>
            </episodes>
            <debug>true</debug>
            <verbose>true</verbose>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-annotate</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-namespace-prefix</artifactId>
                    <version>1.1</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>

      

You have to mvn install project A before project B


Add this plugin to add to your original target class classes

          <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/generated-sources/xjc</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

      

Don't forget to run Maven project - update

+3


source







All Articles