Xsd import from another project, generates java class

I have two projects, A and B. In project A, I have a common.xsd file where I use the cxf-xjc-plugin to generate Java classes that work well. Next, I want to reuse the generated files and inject types from common.xsd in the main.xsd file in project B and not generate the classes from project A again, but there is a problem because I cannot include the full path in the main.xsd file

 <xs:import namespace="..." schemaLocation="PATH_TO_PROJECT_A/common.xsd" /> 


or you are the classpath I read that it is possible to use http, but I cannot use it. Is there a way to use maven or something?


source to share

1 answer

Yes it is possible, keywords:

  • Separate schema compilation with episodes so as not to generate classes that are already generated
  • Catalogs to override the schema location, including pointing to the schema inside the Maven artifact

Disclaimer required: I am the author maven-jaxb2-plugin

who provides these features.


I tried to use a separate compilation of the schema, but unfortunately I cannot expand it. Should I create a separate jar just for the xsd file and use that as a dependency? Now I have a dependency on the whole project A which contains the generated classes and the xsd file

It's enough. You need a JAR with generated classes, XSD files and META-INF/sun-jaxb.episode

. All this is usually generated by default.

Then you can use this JAR as an "episode". XJC will use the resource sun-jaxb.episode

as a required file automatically, and this file basically says something like "generates nothing for the schema in the X namespace, use the following classes instead." This is one part that avoids over-generating classes. This works mostly, but sometimes XJC still generates a few things - they can be safely removed.

Another thing is that you want to use schemas from JAR. This can be done using directories and the custom object recognizer that comes with the default maven-jaxb2-plugin


So just use whatever schemaLocation

, and then rewrite it into a directory file:





All Articles