Avoiding Redundant Class Generation with jaxws-maven-plugin for Shared XSDs in Multiple WSDLs

28 Views Asked by At

I'm working on a Java project where I need to create classes for WSDL and XSD files using the jaxws-maven-plugin. My challenge is that I'm ending up with redundant classes. This issue arises because both of my WSDL files (Foo.wsdl and Bar.wsdl) use the same XSD files (Commons.xsd and Errors.xsd).

I'm looking for a way to generate classes for Commons.xsd and Errors.xsd only once and then reuse them across my WSDL files. Below is the structure of my Java resources folder and the current configuration of my plugin:

Java Resources Folder Structure:

src/main/resources/wsdl/
├── Foo
│   ├── Foo.wsdl
│   ├── FooResponse.xsd
│   ├── FooRequest.xsd
│   ├── Commons.xsd
│   └── Errors.xsd
└── Bar
    ├── Bar.wsdl
    ├── BarResponse.xsd
    ├── BarRequest.xsd
    ├── Commons.xsd
    └── Errors.xsd

Plugin Configuration:

<plugin>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>4.0.2</version>
    <configuration>
        <extension>true</extension>
        <destDir>${classesDir}</destDir>
        <sourceDestDir>${sourcesDir}</sourceDestDir>
        <wsdlLocation>classpath:wsdl/*</wsdlLocation>
        <wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
    </configuration>
    <executions>
        <execution>
            <id>Foo</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <packageName>com.provider.schema.foo</packageName>
                <wsdlFiles>
                    <wsdlFile>Foo/Foo.wsdl</wsdlFile>
                </wsdlFiles>
            </configuration>
        </execution>
        <execution>
            <id>Bar</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <packageName>com.provider.schema.bar</packageName>
                <wsdlFiles>
                    <wsdlFile>Bar/Bar.wsdl</wsdlFile>
                </wsdlFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

Example of XSD import in WSDL:

<wsdl:types>
    <xsd:schema targetNamespace="http://www.provider.com/FOO">
        <xsd:import namespace="http://www.provider.com/schema" schemaLocation="FooResponse.xsd"/>
        <xsd:import namespace="http://www.provider.com/schema" schemaLocation="FooRequest.xsd"/>
        <xsd:import namespace="http://www.provider.com/schema" schemaLocation="Commons.xsd"/>
        <xsd:import namespace="http://www.provider.com/schema" schemaLocation="Errors.xsd"/>
    </xsd:schema>
</wsdl:types>

How can I efficiently generate the classes for shared XSD files without redundancy and ensure they are properly utilized by each WSDL?

I attempted to use a single execution with multiple WSDL files, but this resulted in the ObjectFactory being overwritten by the last WSDL file in the list.

0

There are 0 best solutions below