Legacy Knowledge Base
Published Sep. 10, 2025

Errors calling an external SOAP web service related to javax.xml.ws.spi.Provider or com.sun.xml.ws.spi.ProviderImpl after upgrading to Java 11

Written By

Jorge Diaz

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

We have developed a custom login pre-action module where we want to call an external SOAP web service, this module was working on older Liferay versions.

After upgrading to Java 11, if we try calling this external SOAP web service, we are getting errors related to javax.xml.ws.spi.Provider or com.sun.xml.ws.spi.ProviderImpl

The root cause of the issue is the deprecation of JAX-WS (java.xml.ws) in the Java 11 JVM.

To execute the code in Java 11, we have tried several options having the following errors:

  • Using javax.xml.ws:jaxws-api dependencies:

2023-08-14 11:17:15.934 ERROR [http-nio-8080-exec-5][CustomLoginPreAction:189] Error: javax.xml.ws.WebServiceException: Error while searching for service [javax.xml.ws.spi.Provider]
javax.xml.ws.WebServiceException: Error while searching for service [javax.xml.ws.spi.Provider]
        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.firstByServiceLoader(ServiceLoaderUtil.java:70)
        at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:89)
        at javax.xml.ws.spi.Provider.provider(Provider.java:96)
        at javax.xml.ws.Service.(Service.java:112)

[...ommited lines...]

Caused by: java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: com.liferay.jaxws.osgi.bridge.Provider not a subtype
        at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:589)
        at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1237)
        at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1265)
        at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1300)
        at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1385)
        at javax.xml.ws.spi.ServiceLoaderUtil.firstByServiceLoader(ServiceLoaderUtil.java:63)
        ... 106 more
  • Using jakarta.xml.ws:jakarta.xml.ws-api dependencies:
2023-08-13 17:31:06.035 ERROR [http-nio-8080-exec-10][CustomLoginPreAction:190] Error: jakarta.xml.ws.WebServiceException: Provider com.sun.xml.ws.spi.ProviderImpl not found
jakarta.xml.ws.WebServiceException: Provider com.sun.xml.ws.spi.ProviderImpl not found
        at jakarta.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:35)
        at jakarta.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:32)
        at jakarta.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:76)
        at jakarta.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:110)
        at jakarta.xml.ws.spi.Provider.provider(Provider.java:64)
        at jakarta.xml.ws.Service.(Service.java:82)

[...ommited lines...]

Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.spi.ProviderImpl
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1412)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
        at com.liferay.shielded.container.internal.ShieldedContainerClassLoader.findClass(ShieldedContainerClassLoader.java:79)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at jakarta.xml.ws.spi.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:62)
        at jakarta.xml.ws.spi.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:97)
        at jakarta.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:73)
        ... 163 more
How can we avoid these errors?

Environment

  • Liferay DXP 7.2
  • Liferay DXP 7.3
  • Liferay DXP 7.4

Resolution

After upgrading to Java 11, you have to use the jakarta.xml.ws:jakarta.xml.ws-api dependencies, but to avoid the ClassNotFoundException error you have to:

Fix module dependencies at compilation time

Add an additional dependence to com.sun.xml.ws:jaxws-rt in order to include the jaxws-rt.jar library.

There are several examples of how to replace java.xml.ws (JAX-WS) dependency with jakarta.xml.ws + com.sun.xml.ws after upgrading to Java 11, see:

Fix classloader problems at execution time

On the other hand, it is possible that even if you add this dependency in the OSGI module at compile time, the ProviderImpl class wouldn't be probably found at runtime.

In order to avoid this, you can make a change to the class loader of the current thread before calling the web service and restore it after the call, you have an example below:

Thread currentThread = Thread.currentThread();

ClassLoader threadClassLoader = currentThread.getContextClassLoader();
ClassLoader correctClassLoader = this.getClass().getClassLoader();

try {
//we are changing the classloader of the current thread
currentThread.setContextClassLoader(correctClassLoader);

// ===> Insert here the custom code that calls the external web service <===
}
finally {
//we are restoring the previous classloader of the thread to avoid problems
currentThread.setContextClassLoader(threadClassLoader);
}

 

 

 

Did this article resolve your issue ?

Legacy Knowledge Base