0

I have written a Office.xsd

<?xml version="1.0" encoding="windows-1252" ?>

<xsd:element name="name" type="xsd:string" />

<xsd:complexType name="Employee">
    <xsd:sequence>
        <xsd:element name="entry_time" type="xsd:decimal"
            minOccurs="0" />
        <xsd:element name="exit_time" type="xsd:decimal"
            minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>

 <xsd:complexType name="Furniture">
    <xsd:sequence>
        <xsd:element name="name" type="xsd:string"
            minOccurs="0" />
        <xsd:element name="quantity" type="xsd:int"
            minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="Office">
    <xsd:sequence>
        <xsd:element name="name" type="xsd:string" minOccurs="0" />
        <xsd:element name="address" type="xsd:string" minOccurs="0" />
        <xsd:element name="employee" type="Employee"
            minOccurs="0" />
        <xsd:element name="furniture" type="Furniture"
            minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>

I am creating another Institute.xsd in which I have includeded Office.xsd as below

<xsd:include schemaLocation="Office.xsd" />

<xsd:complexType name="Institute">
    <xsd:sequence>
        <xsd:element name="id" type="xsd:in" minOccurs="1" />
        <xsd:element name="name" type="xsd:string" minOccurs="1" />
        <xsd:element name="employee" type="Employee"
            minOccurs="0" />
        <xsd:element name="furniture" type="Furniture"
            minOccurs="0" />
    </xsd:sequence>
</xsd:complexType>

I am using maven-jaxb2-plugin plug-in .. here is my plug-in

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <id>emp</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <forceRegenerate>true</forceRegenerate>
                        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                        <schemaIncludes>
                            <include>Office.xsd</include>
                        </schemaIncludes>
                        <generatePackage>com.nuovo.employee.model</generatePackage>
                    </configuration>
                </execution>
                <execution>
                    <id>inst</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <forceRegenerate>true</forceRegenerate>
                        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                        <schemaIncludes>
                            <include>Institute.xsd</include>
                        </schemaIncludes>
                        <generatePackage>com.nuovo.institute.model</generatePackage>
                        <args>
                            <arg>-XtoString</arg>
                            <arg>-Xcopyable</arg>
                            <arg>-Xequals</arg>
                        </args>
                        <plugins>
                            <plugin>
                                <groupId>org.jvnet.jaxb2_commons</groupId>
                                <artifactId>jaxb2-basics</artifactId>
                                <version>0.6.4</version>
                            </plugin>
                        </plugins>
                    </configuration>
                </execution>
            <dependencies>
                <dependency>
                    <groupId>com.datastax.cassandra</groupId>
                    <artifactId>cassandra-driver-core</artifactId>
                    <version>3.1.3</version>
                </dependency>
                <dependency>
                    <groupId>com.datastax.cassandra</groupId>
                    <artifactId>cassandra-driver-mapping</artifactId>
                    <version>3.1.3</version>
                </dependency>
            </dependencies>
        </plugin>

I am getting Employee.java, Furniture.Java and Office.java in both packages (com.nuovo.institute.model and com.nuovo.employee.model). Not only in Institute.xsd, I have to use only Employee as type in another xsds also in some XSDs i have to use only Furniture as type how do I make sure these classes not duplicated in other packages and how to make these generated classes(Employee.java, Furniture.java and Office.java) as common to other classes

Sat
  • 3,520
  • 9
  • 39
  • 66

1 Answers1

0

In order to avoid duplicated classes with maven-jaxb2-plugin, you have to use modular - aka episodic - schema compilation, i.e. using episodes, and XML catalog(s) referencing the XSD file(s) from Maven artifact resources. However, it is a known issue that this does not work with schema include but only with schema import. So either you change include to import in Institude.xsd, or use one of the two options mentioned on the known issue's page:

  • Write the META-INF/sub-jaxb.episode file manually.
  • Write your own XJC plugin to generate this file without map="false". It's not hard, see com.sun.tools.xjc.addon.episode.PluginImpl.

Also make sure you upgrade your versions of the maven-jaxb2-plugin and jaxb2-basics, they are pretty old.

cdan
  • 3,470
  • 13
  • 27