0

I am successfully generating java classes from multiple wsdl endpoints using maven-jaxb2-plugin.

This is one execution:

                <execution>
                    <id>generateDelta</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generatePackage>com.somepackage1</generatePackage>
                        <schemas>
                            <schema>
                                <url>
                                    wsdl_url
                                </url>
                            </schema>
                        </schemas>
                    </configuration>
                </execution>

The issue here is that I have multiple executions, thus generating multiple class, each execution saving the classes in different package.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Bapiret2", propOrder = {...})

One of the class Babiret2.java is generated in more then one package (so, it comes from multiple wdsls)

When I execute code that uses this stubs, in a unit test for example I get the following exception:

    org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
Two classes have the same XML type name "{urn:sap-com:document:sap:soap:functions:mc-style}Bapiret2". Use @XmlType.name and @XmlType.namespace to assign different names to them.
    this problem is related to the following location:
        at com.somepackage1.Bapiret2
    this problem is related to the following location:
        at com.somepackage2.Bapiret2

I found some possible fixes like adding in configuration under args tag

-XautoNameResolution

arg, it did not worked

I tested if changing the XmlType name attribute works and it does. Also adding namespace to XmlType works.

The problem is that I do not know how to add this with maven when generating the classes

aurelius
  • 3,946
  • 7
  • 40
  • 73
  • I tested if changing the XmlType name attribute works and it does. Also adding namespace to XmlType works. The problem is that I do not know how to add this with maven when generating the classes – aurelius Jul 12 '17 at 12:03

2 Answers2

1

For each wsdl url, inside the configuration element, you should specify both schemaDirectory and generatePackage elements, that should point to names different from other ones, because of schemaDirectory has as a side effect clearing the specified directory.

ugo
  • 284
  • 1
  • 2
  • 10
1

Your problem belongs to JAXBContext when both classes from different packages, but with the same NameSpace are known by it. So, there are multiple things you need to consider:

  1. Is JAXBContext creation in your hands? If so - do you really need both classes in the same JAXBContext? Maybe you can use two different contexts for each use case? I mean when Bapiret2 used from somepackage1 and from somepackage2.

If it is not possible:

  1. Are those two classesBapiret2 generated from the same XSD Schema and actual structure is the same?

    if yes - you may need to reconsider your generated packages structure.

    You can generate only one Bapiret2 class for all your wsdl. There are number of ways to do that usually by adding extra mapping parameters to underlying XJC compiler like

      -p {namespace}={package Name}
    

Just check Plugin documentation how to do that... (note: there is a side effect: in the package there will be class only from last plugin execution.

  1. If Bapiret2 XML Elements in different XSD have same namespace, but different structure (...unfortunately pretty common case when webservice developers disobey main purpose of namespace ...) then it is a worst case.

In that case I use first solution above - different JAXBContexts

But anyway there are some solution below. (I never tried it, but it seems like people are happy with that :-)

getting-the-jaxb-exception-like-two-classes-have-the-same-xml-type-name

extending-jaxb-representing-annotations.html

PS. Manual (or through some script) changes after generation still the option...

Vadim
  • 4,027
  • 2
  • 10
  • 26
  • [ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate (generateVehicle) on project maven.module: Error parsing the command line [[-p {namespace}={vehicle}, -episode, C:\...\target\generated-sources\xjc\META-INF\sun-jaxb.episode]]: unrecognized parameter -p {namespace}={vehicle} -> [Help 1] – aurelius Jul 12 '17 at 14:05
  • -p {namespace}={vehicle} in the configuration tag – aurelius Jul 12 '17 at 14:05
  • not like that it is a parameter for xjc command line. {} means put your actual values: i.e `-p http://foo.com/schema/myservice=com.foo.schema.myservice` Different maven plugins use different configurations to set it and I'm not sure about maven-jaxb2-plugin because I did not use it for such purpose for long time. ... It seems like `` settings... – Vadim Jul 12 '17 at 15:06