Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

In this tutorial, we’ll show how to configure the JAX-WS maven plugin to generate Java classes from a WSDL (web service description language) file. As a result, we’ll be able to call web services using the generated classes easily.

2. Configuring Our Maven Plugin

First, let’s include the latest version of JAX-WS Maven plugin with the wsimport goal in the build plugins section of our pom.xml file:

<build>
    <plugins>
        <plugin>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>4.0.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

In short, the wsimport goal generates JAX-WS portable artifacts for use in JAX-WS clients and services. The tool reads a WSDL file and generates all required web service development, deployment, and invocation artefacts.

2.1. WSDL Directory Configuration

Within our Maven plugin section, the wsdlDirectory configuration property informs the plugin where our WSDL files are located. In this example, we’ll tell the plugin to get all WSDL files in our project’s src/main/resources directory:

<plugin>
    ...
    <configuration>
        <wsdlDirectory>${project.basedir}/src/main/resources/</wsdlDirectory>
    </configuration>
</plugin>

2.2. WSDL Directory-Specific Files Configuration

Additionally, we can use the wsdlFiles configuration property to define a list of WSDL files to consider when generating the classes:

<plugin>
    ...
    <configuration>
        <wsdlDirectory>${project.basedir}/src/main/resources/</wsdlDirectory>
        <wsdlFiles>
            <wsdlFile>file1.wsdl</wsdlFile>
            <wsdlFile>file2.wsdl</wsdlFile>
            ...
        </wsdlFiles>
    </configuration>
</plugin>

However, when the wsdlFiles property isn’t set, all the files in the directory specified by the wsdlDirectory property will be considered.

2.3. WSDL URLs Configuration

Alternatively, we can configure the plugin’s wsdlUrl configuration property:

<plugin>
    ...
    <configuration>
        <wsdlUrls>
            <wsdlUrl>http://localhost:8888/ws/country?wsdl</wsdlUrl>
        ...
        </wsdlUrls>
    </configuration>
</plugin>

To use this option, the server hosting the URL for the WSDL file must be up and running so that our plugin can read it.

2.4. Configuring the Generated Classes Directory

Next, in the packageName property, we can set up the generated classes package name, and in the sourceDestDir, the output directory:

<plugin>
    ...
    <configuration>
        <packageName>com.baeldung.soap.ws.client</packageName>
        <sourceDestDir>
            ${project.build.directory}/generated-sources/
        </sourceDestDir>
    </configuration>   
</plugin>

As a result, our final version of the plugin configuration using the wsdlDirectory option is:

<plugin>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>4.0.2</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <wsdlDirectory>${project.basedir}/src/main/resources/</wsdlDirectory>
        <packageName>com.baeldung.soap.ws.client</packageName>
        <sourceDestDir>
            ${project.build.directory}/generated-sources/
        </sourceDestDir>
    </configuration>
</plugin>

3. Running the JAX-WS Plugin

Finally, with our plugin configured, we can generate our classes with Maven and check the output logs:

mvn clean install
[INFO] --- jaxws:4.0.1:wsimport (default) @ jaxws ---
[INFO] Processing: file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl
[INFO] jaxws:wsimport args: [-keep, -s, 'D:\projetos\baeldung\tutorials\maven-modules\maven-plugins\jaxws\target\generated-sources', -d, 'D:\projetos\baeldung\tutorials\maven-modules\maven-plugins\jaxws\target\classes', -encoding, UTF-8, -Xnocompile, -p, com.baeldung.soap.ws.client, "file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl"]
parsing WSDL...
Generating code...

4. Check Generated Classes

After running our plugin, we can check the output in the folder target/generated-sources configured in the sourceDestDir property.

The generated classes can be found in com.baeldung.soap.ws.client as configured in the packageName property:

com.baeldung.soap.ws.client.Country.java
com.baeldung.soap.ws.client.CountryService.java  
com.baeldung.soap.ws.client.CountryServiceImplService.java
com.baeldung.soap.ws.client.Currency.java
com.baeldung.soap.ws.client.ObjectFactory.java

5. Conclusion

In this article, we saw how to generate Java classes from a WSDL file using the JAX-WS plugin. As a result, we’re now able to create a web service client and use the generated classes to call our services.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW