WildDev
WildDev

Reputation: 2367

Maven JAXB 2 Plugin - how to setup to use cross scheme dependencies

Using maven-jaxb2-plugin to generate JAXB classes for two WSDL schemas that are related to each other.

The classes generated like this:

com - accounts
   |- payments
   |- other

maven-jaxb2-plugin is set up like this:

<plugin>
   <groupId>org.jvnet.jaxb2.maven2</groupId>
       <artifactId>maven-jaxb2-plugin</artifactId>
       <version>0.13.1</version>
       <executions>
           <execution>
               <id>unipayments</id>
               <goals>
                   <goal>generate</goal>
               </goals>
               <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <args>
                        <arg>-npa</arg>
                    </args>
                    <schemas>
                        <schema>
                            <url>http://...accounts?wsdl</url>
                        </schema>
                    </schemas>
               </configuration>
            </execution>
            <execution>
                <id>accounts</id>
                <goals>
                   <goal>generate</goal>
                </goals>
                <configuration>
                   <schemaLanguage>WSDL</schemaLanguage>
                   <args>
                       <arg>-npa</arg>
                   </args>
                   <schemas>
                       <schema>
                          <url>http://...payments?wsdl</url>
                       </schema>
                    </schemas>
                </configuration>
             </execution>
    </executions>
</plugin>

The annotations of the one of the generated classes (almost the same anywhere):

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "inputTemplate", namespace = "http://...payments", propOrder = {})
public class InputTemplate {...}

The issue is SOAP accounts JAXB classes have the nested element of the class specified above which came from another payments scheme. So, Marshaller throws the exception like this when I query to the object of accounts service that has payment's inputTemplate as child:

unexpected element (uri:"http://...payments", local:"inputTemplate"). 
Expected elements are <{}inputTemplate>

Don't know why it happens though, the each class has namespace specified.

So, how to let JAXB classes with cross scheme dependency work using this plugin?

Upvotes: 0

Views: 135

Answers (1)

lexicore
lexicore

Reputation: 43671

This:

unexpected element (uri:"http://...payments", local:"inputTemplate"). Expected elements are <{}inputTemplate>

Actually points not to a problem with schema dependencies but rather to a problem with namespaces. The inputTemplate element is known but it is expected in the default namespace. Probably wrong elementFormDefault or something like this.

To answer your question, inter-schema dependencies are best handled if you compile your schemas separately (separate Maven modules) and the include dependencies as episodes.

https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Episodes

Upvotes: 1

Related Questions