tags:

views:

189

answers:

1

I've got two Java projects, both generate Java classes based on a schema definition, I'm using xjc to create the classes.

My second project depends on a class from the first project, and in particular, one of the classes I'd like to generate in my second project needs to use one of the types from the first project.

To accomplish this dependency at the schema level, I'm using a simple xsd:import to map the namespace to a particular schema.

JAXB works just fine with this condition, except it also generates the first project's types in the second project. So after running have something like this:

Project A
  +-- com.foo.bar
    +-- TypeA

Project B
  +-- com.foo.asdf
    +-- TypeB
  +-- com.foo.bar
    +-- TypeA

The second "TypeA" is undesirable, and I'd like to never generate it in the first place. How do I instruct JAXB not to generate the classes for "TypeA" that it finds as a result of the import statement?

+3  A: 

Customize it as a DOM element (<jaxb:dom/>).

<xs:element name="a" type="a:Type">
  <xs:annotation>
    <xs:appinfo>
      <jaxb:dom/>
    </xs:appinfo>
  </xs:annotation>
</xs:element>

You may be also interested in separate/episodic schema compilation.

lexicore
Maybe I misunderstood...but I added this annotation to the element in ProjectB and recompiled, I still got ProjectA's types, I tried removing the import, and that generates an error. Can you clarify your example a bit?
Mark E
jaxb:dom only helps to remove the dependency from B to A. You will get a DOM Element instead of AType - so there is not compile-time dependency.A more correct solution is with episodes. Check this Maven project example:http://download.java.net/maven/2/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-sample-episode/See also this blog entry from Kohsuke:http://weblogs.java.net/blog/2006/09/05/separate-compilation-jaxb-ri-21
lexicore
Thanks -- using episodes fixes my issue.
Mark E