Cuga Cuga - 1 year ago 173
Java Question

How to generate Java files from WSDL when 'lang' already defined?

I'm trying to turn a WSDL file into Java code using

by running this command (which should work from anyone's machine):

wsimport -J-Djavax.xml.accessExternalDTD=all -J-Djavax.xml.accessExternalSchema=all -B-XautoNameResolution -Xnocompile

However, I keep getting this error:

[ERROR] 'lang' is already defined
line 93 of

[ERROR] (related to above error) the first definition appears here
line 43 of

[ERROR] 'space' is already defined
line 102 of

[ERROR] (related to above error) the first definition appears here
line 89 of

[ERROR] 'base' is already defined
line 109 of

[ERROR] (related to above error) the first definition appears here
line 113 of

[ERROR] 'specialAttrs' is already defined
line 117 of

[ERROR] (related to above error) the first definition appears here
line 157 of

I've spent hours googling this to try and find the solution. I'm relatively convinced I need to specify a binding file with the
-b binding.xml

However, I'm having a very hard time figuring out how to create that binding file. Here's what I've attempted:


<jaxb:bindings xmlns:jaxb=""
<jaxb:bindings schemaLocation="">
<jaxb:bindings node="//xs:attribute[@name='lang']">
<jaxb:property name="langAttribute"/>

Then with this in place, I try running with the binding file by:

wsimport -J-Djavax.xml.accessExternalDTD=all -J-Djavax.xml.accessExternalSchema=all -B-XautoNameResolution -Xnocompile -b binding.xml

And now I get:

[ERROR] XPath evaluation of "//xs:attribute[@name='lang']" results in empty target node
line 6 of file:/Users/name/git/foo/bar/src/main/resources/wsdl/binding.xml

I've tried many other combinations of the binding file's XPath... I figure I need to rename the attribute of all elements from 'lang' to something else, but I really have been having a hard time figuring it out.

Thanks in advance for any help!

Solution Update:
I got past this error by downloading the schemas locally, and wherever there was a reference to
, I edited the XML to point to my local copy of the file on the file system.

I.e. opened up each *.xsd file where there was reference to these files, and updated each line from something like this:

<xsd:import namespace="" schemaLocation=""/>

To this:

<xsd:import namespace="" schemaLocation="./xml.xsd"/>

After that, it was able to generate the Java classes using the
syntax above (did require one small binding file, but that was related to an vendor-defined class).

Answer Source

You've bound your xs prefix to the XML namespace, but it should be bound to the XML Schema namespace


Another problem you'll face is that your schema seem to address xml.xsd via two different locations: and That will get you a lot fo duplicates. You can try to resolve them via catalogs like:


(And the use it with -catalog.)

But I'm not sure this will work. In a similar situation I've created a full local copy of schemas I needed to compile and patched them to use uniform schema locations.

I tried downloading the schemas and xml files locally, but am not sure how to tell wsimport to look for the local copies instead of going out to the internet. If I have a copy of xsd.xml locally... is there a way to tell wsimport to use that instead of any it may find on the internet?

I'm not exactly sure about wsimport but generally it is done with catalogs. Assume you've downloaded schemas from in the directory w3c. Then you'll have a catalog file like


Then you should be able to use this catalog file via wsimport -catalog .... wsimport or underlying schema compiler xjc should get your schema from w3c/2001/xml.xsd then.

However, I've never tried it with wsimport, I just routinely use it with maven-jaxb2-plugin.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download