Migration to Jakarta: ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl

限于喜欢 提交于 2020-01-05 05:27:29

问题


While migrating from Java 8 to Java 11 and switching from EE to the newest Jakarta libraries according to https://wiki.eclipse.org/New_Maven_Coordinates and Maven central, we get the following runtime exception in our (still SOAP-based) client application:

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:31)
        at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:28)
        at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:73)
        at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:82)
        at javax.xml.ws.spi.Provider.provider(Provider.java:66)
        at javax.xml.ws.Service.<init>(Service.java:82)
        at [...]
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at javax.xml.ws.spi.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:60)
        at javax.xml.ws.spi.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:93)
        at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:71)
        ... 5 more

The solution described in Getting java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl despite the dependencies are defined doesn't work and doesn't use Jakarta.

If I'm not wrong, the Jarkarta libraries shouldn't contain "com.sun.xml."packages or reference such, but javax.xml.ws.spi.Provider obviously STILL DOES reference such class:

private static final String DEFAULT_JAXWSPROVIDER =
        "com.sun"+".xml.internal.ws.spi.ProviderImpl";

So, does anyone know if there is a Jakarta equivalent to the missing library containing ProviderImpl, or how I could workaround the problem with Jakarta?

Thanks in advance!


回答1:


I finally found a workaround for my problem. According to the answer given in How to use WebServices on Java 11? package javax.jws does not exist the reference implementation of JAX-WS should be included with Java 11:

<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-ri</artifactId>
  <version>2.3.2</version>
  <type>pom</type>
</dependency>

Unfortunately, compiling our project with this dependency using the latest maven-compile-plugin 3.8.0 causes the exception described in https://jira.apache.org/jira/browse/MCOMPILER-355. It should be fixed in 3.8.1 but the version is not available yet.

As a workaround I got our project working with the hint given in Getting java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl despite the dependencies are defined, combined with an additional dependency (namely resolver that is also linked in the pom.xml of jaxws-ri) to avoid an subsequent java.lang.ClassNotFoundException: com.sun.org.apache.xml.internal.resolver.CatalogManager:

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

<dependency>
    <groupId>com.sun.org.apache.xml.internal</groupId>
    <artifactId>resolver</artifactId>
    <version>20050927</version>
</dependency>

Maybe this helps someone running into the same problem.



来源:https://stackoverflow.com/questions/55748392/migration-to-jakarta-classnotfoundexception-com-sun-xml-internal-ws-spi-provid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!