Mythbuster
Mythbuster

Reputation: 57

Generate Classes from multiple webservices using maven

I have a POM where I am using JAXB2 plugin to generate code from mulitple webservices (wsdl).


<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <!-- maven-jaxb2-plugin -->
    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
            <execution>
            <id>Bus</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service1?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.business</generatePackage>
                </configuration>
            </execution>
            <execution>
            <id>Ser</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service2?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.search</generatePackage>
                </configuration>
            </execution>
            <execution>
            <id>Tab</id>                    
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service3?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.table</generatePackage>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

The generated class files are all included in all the Packages. Therefore

It appears that namespaces are not handled correctly as the classes for wsdl1,2,3 are combined in all the 3 packages.

How to ensure that these packages include the specific classes specified in the wsdl?

Upvotes: 2

Views: 811

Answers (1)

Jay Jordan
Jay Jordan

Reputation: 743

Those asterisk on each side of your <url> and <generatePackage> attributes are wild card characters.

See this example from http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/example_xjc_basic.html

<project>
...
<dependencies>
    <!--
        You need the JAXB API to be able to annotate your classes.
        However, starting with Java 6 that API is included in the
        Java SE platform so there is no need to declare a dependency.
    -->
    ...
</dependencies>
...
<build>
    <pluginManagement>
        <plugins>
            <!--
                If we e.g. execute on JDK 1.7, we should compile for Java 7 to get
                the same (or higher) JAXB API version as used during the xjc execution.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>${project.version}</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The package of your generated sources -->
                <packageName>com.example.myschema</packageName>
            </configuration>
        </plugin>
        ...
    </plugins>
<build>
...
</project>

I would definitely take the * and ** of the beginning of those lines. I found the answer to your question pretty quickly by going to https://github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet

Upvotes: 1

Related Questions