How to generate classes from wsdl using Maven and wsimport?

To generate classes from WSDL, all you need is build-helper-maven-plugin and jaxws-maven-plugin in your pom.xml
Make sure you have placed wsdl under folder src/main/resources/wsdl and corresponding schema in src/main/resources/schema, run command “mvn generate-sources” from Project root directory.

C:/Project root directory > mvn generate-sources

generated java classes can be located under folder

target/generated/src/main/java/com/raps/code/generate/ws.

pom.xml snippet

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/generated/src/main/java</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.12</version>
    <configuration>
        <wsdlDirectory>${project.basedir}/src/main/resources/wsdl</wsdlDirectory>
        <packageName>com.raps.code.generate.ws</packageName>
        <keep>true</keep>
        <sourceDestDir>${project.build.directory}/generated/src/main/java</sourceDestDir>
    </configuration>
    <executions>
        <execution> 
            <id>myImport</id>
            <goals><goal>wsimport</goal></goals>
        </execution>
    </executions>
</plugin>

Leave a Comment