Getting java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl despite the dependencies are defined

Getting java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl despite the dependencies are defined

If you encounter the java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl error despite having the necessary dependencies defined in your pom.xml, here’s how to resolve it.

Dependencies for Java 10

For a Java 10 environment, you can use the following dependencies to ensure that your application has access to the required JAX-WS classes:

<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>rt</artifactId>
    <version>2.3.1</version>
</dependency>

Transition to Jakarta

In the current era of Jakarta EE, you may also need to include these updated dependencies:

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>2.3.3</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.3</version>
</dependency>

Clarification on Dependencies

It’s worth noting that the jaxws-rt dependency is still provided by com.sun.xml.ws and not from Jakarta. This can be somewhat confusing, as many implementations have been migrated to Jakarta namespaces. However, this dependency is necessary for your application to function correctly.

Alternative Dependency

If you continue to experience issues, you might want to try including an older version of the rt dependency:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>rt</artifactId>
    <version>2.2.10</version>
</dependency>

Scope Adjustment

Another potential solution is to change the scope of the dependency to import. This can be done as follows:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.2.10</version>
    <type>pom</type>
    <scope>import</scope> 
</dependency>

By following these recommendations, you should be able to resolve the ClassNotFoundException and ensure your application runs smoothly.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *