tags:

views:

42

answers:

2

I have 3 xsd files:

  • a.xsd
  • b.xsd
  • shared.xsd

shared.xsd is imported to both a.xsd and b.xsd using

<xs:import schemaLocation="shared.xsd"/>

shared.xsd defines

<xs:element name="item">
<xs:complexType> ....

If I generate java code using xjc a.xsd and b.xsd is generated into different packages and in each package a separate java class is generated for item. How would it be possible to have a single shared class for item and make a and b use it?

A: 

You can override the package that generated files are put into. This should allow both of the shared objects to go into the same place.

xjc -p com.test a.xsd b.xsd shared.xsd

I think that is what you are looking for.

Chris Dail
wow thanks it works. I always executed xjc a.xsd xjc b.xsd xjc shared.xsdand that way it didnt work. There is only one problem with this solution: the top level element of a.xsd and b.xsd are both called the same ("request" in my case) and unfortunately I cannot change that. With my solution it wasn't problem because each xsd was compiled to different packages, but now the two elements with the same name in the same package conflict. Is there any solution for that?
Peter Szanto
@Peter Szanto, You should be able to use the binding configuration files (.xjb files) to resolve that conflict.
Chris Dail
thanks again, it works! It is amazing there is always something new to learn. Just for the benefit of the public I added the below inline xjb declaration into my xsd <xs:annotation> <xs:appinfo> <jxb:bindings node="//xs:element[@name='request']"> <jxb:class name="EmailauthenticationRequest"/> </jxb:bindings> </xs:appinfo> </xs:annotation>and that generates EmailauthenticationRequest.java which is bound to request in the xml
Peter Szanto
A: 

Either do what @Chris Dail said, or merge a.xsd and b.xsd in one schema file since JAXB looks a the namespace to create the package.

Alexandru Luchian