Skip to content
Advertisement

ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

I have added all the relevant dependencies in build.gradle file. Still, geting below error when I try to run the Invoke SOAP service. Shared dependencies section and error details. Using Java 11. There are lot of answers already on internet, but none of it seems to be working. Any Help/Suggestion would be appreciable.

dependencies {
    implementation 'org.codehaus.groovy:groovy-all:3.0.2'
    implementation 'javax.jws:javax.jws-api:1.1'

    cxfCodegen "jakarta.annotation:jakarta.annotation-api:1.3.5"
    cxfCodegen "jakarta.xml.ws:jakarta.xml.ws-api:2.3.3"
    cxfCodegen "jakarta.xml.bind:jakarta.xml.bind-api:2.3.3"

    //implementation 'org.apache.cxf:cxf-spring-boot-starter-jaxws:3.5.0'
    //implementation 'javax.xml.bind:jaxb-api:2.3.1'
    compile 'javax.xml.ws:jaxws-api:2.3.1'

    implementation 'com.sun.xml.messaging.saaj:saaj-impl:2.0.1'
    implementation 'javax.xml.soap:javax.xml.soap-api:1.4.0'
    implementation 'javax.xml.soap:saaj-api:1.3.5'

    implementation 'com.sun.xml.ws:jaxws-rt:3.0.2'
    implementation 'com.sun.xml.ws:rt:3.0.2'
    implementation 'com.sun.xml.ws:jaxws-ri:3.0.2'
}

Getting below error stacktrace

Exception in thread "main" javax.xml.ws.WebServiceException: Provider com.sun.xml.internal.ws.spi.ProviderImpl not found
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:61)
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:58)
    at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:103)
    at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:112)
    at javax.xml.ws.spi.Provider.provider(Provider.java:96)
    at javax.xml.ws.Service.<init>(Service.java:112)
    at com.example.BLZService.<init>(BLZService.java:40)
    at dummypackage.DummySOAPClient.main(DummySOAPClient.java:21)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

    at javax.xml.ws.spi.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:90)
    at javax.xml.ws.spi.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:123)
    at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:101)
    ... 5 more

Advertisement

Answer

A2A: There are probably some issues in the internal referrencing may be.

You can follow this answer: JDK 11; JAX-WS; Provider com.sun.xml.internal.ws.spi.ProviderImpl not found

Basically the answer says you can try to include an older rt dependency as well:

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

The above is maven pom xml format.

Here is gradle format for you:

implementation 'com.sun.xml.ws:rt:2.3.1'

This will most probably resolve you issue.

EDIT: Post discussion in comments below:

The dependencies that worked are:

implementation 'com.sun.xml.ws:jaxws-rt:2.3.2'
implementation 'com.sun.xml.ws:rt:2.3.2'
implementation 'com.sun.xml.ws:jaxws-ri:2.3.2'

After above dependecies, there was an error related to

com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found

which can be resolved using the compatible SAAJ dependency:

implementation 'com.sun.xml.messaging.saaj:saaj-impl:1.5.1'

Also while adding header there was an issue in adding header to request after the above saaj dependencies were added:

Previous code:

SOAPMessageContext context; 
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = envelope.addHeader();

Updated code which works:

SOAPHeader header = envelope.getHeader();

Refer below link for jaxws-rt runtime dependencies:

https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt/2.3.2

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement