17 de noviembre de 2011

Jax wsimport Two classes have the same XML type name

Tomado Desde jackdevofalltrades 

 

JAX-WS "Two classes have the same XML type name"

When generating the Java classes using wsgen from a WSDL I was getting the following error:

Two classes have the same XML type name "{http://myservice/}foo". Use @XmlType.name and @XmlType.namespace to assign different names to them.
this problem is related to the following location:

As suggested by the exception I tried changing @XmlType but that was fine for me.
This link offers the same solution and it also suggests to change Response classes which I think its an extreme solution.

Anyway in my case the problem was that I generated the classes and I wanted to change the package name.
Everything worked fine, compiled and the webservice deployed successfully.
When viewing the WSDL I got the above error.
In my case the solution was just to update the new namespace in the Webmethod attribute.

@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "foo", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.foo")
@ResponseWrapper(localName = "fooResponse", targetNamespace = "http://fooservice/", className = "com.foo.service.generated.FooResponse")

The attribute className had to be updated :(