1

I have 3 XSDs linked together:

schema1.xsd
    imports namespace="x:y:z" schemaLocation= "schemaDefinitions.xsd"
    includes schema2.xsd
schema2.xsd
    imports namespace="x:y:z" schemaLocation= "schemaDefinitions.xsd"
    includes schema3.xsd
schema3.xsd
    imports namespace="x:y:z" schemaLocation= "schemaDefinitions.xsd"

These xsds are provided by an outside source and cannot be changed.

Previously my project used standard JAXB with classes created at compile time. I currently am switching to Dynamic JAXB MOXY (runtime) and now receive the following error on my DynamicJAXBContextFactory.createContextFromXSD() line, which uses schema1.xsd for FileInputStream:

Exception in thread "main" java.lang.ExceptionInInitializerError at 
    TestTool.JavaRoot.TestTools.MainTool.main(MainTool.java:55)
    Caused by: Exception [EclipseLink-50040] (Eclipse Persistence Services - 
    2.6.2.v20151217-774c696): 
    org.eclipse.persistence.exceptions.JAXBException
Exception Description: Error creating DynamicJAXBContext.
    Internal Exception: org.xml.sax.SAXParseException; systemId: 
    file:///public/SITE1/config/schema/SchemaDefinitions.xsd; lineNumber: 
    xyz; columnNumber: xyz; 'xyz' is already defined

I have determined the cause is the fact that all three schemas import schemaDefinitions.xsd. If I remove the import statement from schema2 and schema3 the error is resolved. This error was not present with the previous implementation of jaxb and the xsds have not changed since switching to MOXY.

Questions:

  1. Is it legal/ valid for the xsds to import/ include in this way

  2. What are possible work arounds since I can not modify the XSDs? Perhaps modifications to the bindings xjb file?

JavaBeast
  • 766
  • 3
  • 11
  • 28

2 Answers2

1

Another answerer may be able to help directly with any MOXy configuration support in the area of duplicate declarations, but at purely the XSD level:

  1. Unfortunately the W3C XSD Recommendation allows implementation-dependent behavior to occur when an XSD is imported multiple times. (See last note in 4.2.3 References to schema components across namespaces)
  2. Depending upon the underlying XSD processor upon which MOXy is built, you may be able to set a flag to allow/disallow multiple imports. For Xerces, see honour-all-schemaLocations; for Saxon, see multipleSchemaImports.1

See also Is it an error to import the same XSD multiple times?


1 Note a pending improvement on the semantics of multipleSchemaImports.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thanks, this gives me some things to look into.Unfortuantly MOXY doesnt seem to have a lot of followers to assist. Perhaps i would set this saxon flag in my EntityResolver? The examples ive found with moxy dont seem to cover this issue. I also played with the noCorrectnessCheck flag (shown at: http://www.eclipse.org/eclipselink/documentation/2.5/solutions/jpatoxml006.htm) but that didnt seem to help much – JavaBeast Jun 20 '17 at 23:13
  • `honour-all-schemaLocations` and `multipleSchemaImports` are typically set via parser configuration file, command line switch, or possibly API parameter. – kjhughes Jun 20 '17 at 23:42
  • hmm im not really sure how to apply that to MOXY terminology, all this stuff is new to me. At this point Im half temped to read the file in and remove the import lines by hand. But that is so very hackish i probably couldnt live with myself – JavaBeast Jun 21 '17 at 01:02
  • See if [**this answer**](https://stackoverflow.com/a/13613096/290085) helps. If not, sorry, but you'll have to tap into a deeper source of JAXB/MOXy help. Good luck. – kjhughes Jun 21 '17 at 01:44
1

Resolved issue by turning off error check with putting the following line in MyEntityResolver.java class:

System.setProperty("com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.noCorrectnessCheck", "true");

I had tried this in my main java class before, apparently thats the wrong place for it!

JavaBeast
  • 766
  • 3
  • 11
  • 28
  • Glad you were able to solve your problem. Should you ever determine a solution that still allows validation to occur, please update your answer. Thanks. – kjhughes Jun 21 '17 at 13:59