29

I am looking for compatible combination of org.apache.cxf:cxf-spring-boot-starter-jaxws with jaxws-api/jaxws-ri on Java 10+.

Our application works fine on Java 8.

Also on Java 9 & 10 with --add-modules=java.se.ee.

But, when i remove this option and add following dependecies:

compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.0'
compile group: 'com.sun.xml.ws', name: 'jaxws-ri', version: '2.3.0.2', ext: 'pom'
compile group: 'com.sun.xml.ws', name: 'jaxws-rt', version: '2.3.0.2', ext: 'pom'

common dependencies (with/without --add-modules in java 9/10, or java 8):

compile('org.apache.cxf:cxf-spring-boot-starter-jaxws:3.2.6')

I become:

Caused by: java.lang.NoSuchMethodError: javax.jws.WebMethod.exclude()Z
    at org.apache.cxf.jaxws.support.JaxWsServiceConfiguration.isOperation(JaxWsServiceConfiguration.java:190)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.isValidMethod(ReflectionServiceFactoryBean.java:1962)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.createInterface(ReflectionServiceFactoryBean.java:999)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:461)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:695)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:530)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:263)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:103)
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:168)
    at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:460)
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:338)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:255)
    at .....
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 44 more
Lii
  • 11,553
  • 8
  • 64
  • 88
amjr
  • 291
  • 1
  • 3
  • 5
  • Few points that I could collect, trying to debug a similar setup... 1. a transitive dependency of `com.sun.xml.ws:jaxws-ri:2.3.0.2` which is `javax.jws:jsr181-api:jar:1.0-MR1` brings in the interface `WebMethod` which does have the method `exclude`... 2. Can you make sure no other dependency is bringing in the same interface with a different implementation? 3. Also, could you detail out in the question, how you are building/executing your application? – Naman Aug 17 '18 at 17:25
  • ad 3) @SpringBootTest – amjr Aug 20 '18 at 06:28
  • ad 2) only spring-boot-starter-web spring-boot-starter-test 2.0.3. This is small application with small amount of dependencies and JAXWS is not necessary. I want also to open general discussion about migration, if application is more complex. – amjr Aug 20 '18 at 06:34
  • Simply use https://github.com/codecentric/cxf-spring-boot-starter - it does the integration of Apache CXF and Spring Boot without any hassle for the developer. And it solves your upgrade problems to Java 11 (and 15 :) ). It also adds capabilities of handling all the JAX-B class generation automatically using the https://github.com/codecentric/cxf-spring-boot-starter-maven-plugin - and also generates every Spring Boot classes 100% only from your `.wsdl` file (implementing the contract first concept). But it also works in client-only mode. – jonashackt Jan 07 '21 at 15:38

3 Answers3

30

Note sure about sprint boot, but to get JAXWS working in Java 11, I used

<profiles>
    <!-- add back the jaxws SOAP dependendies which were removed in JDK11 -->
    <profile>
        <id>jdk11</id>
        <activation>
            <jdk>[11,)</jdk>
        </activation>
        <!-- tested working with OpenJDK 11.0.8 -->
        <dependencies>
            <dependency>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>jaxws-rt</artifactId>
                <version>2.3.3</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.ws</groupId>
                <artifactId>rt</artifactId>
                <version>2.3.3</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>
user1791121
  • 328
  • 3
  • 8
  • If you need to generate clients from wsdl check this question https://stackoverflow.com/questions/52857820/cxf-codegen-maven-plugin-doesnt-work-openjdk-11 – JuanMoreno Dec 04 '18 at 05:27
  • 3
    The jaxws-rt.jar uses 3 jdk internal APIs which are removed in java 11.0.5. Is there any other alternative library to use for this jar? Any other jar which is compatible with Java 11? – Rohit Gaikwad Nov 30 '19 at 01:40
  • for wsdl generation, if found a workable solution combining Cassian's [answer](https://stackoverflow.com/questions/18338196/how-to-generate-classes-from-wsdl-using-maven-and-wsimport) with this one – Paul May 25 '20 at 14:11
22

The documentation regarding this removal (JEP 320) has a topic called Risks and Assumptions followed by Java EE modules in which they suggest alternatives for the removals, like jaxws-ri and jaxb-ri.

In my case I was using the javax.jws package in Java 8 and it got removed in Java 11. So as the JEP suggests, I just had to add the following dependency to get it working again on Java 11:

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

In your case you may need other dependencies as well, just take a look at the JEP suggestions.

Rafael Renan Pacheco
  • 2,138
  • 21
  • 22
  • 1
    I have a similar problem, and I still can’t find a solution. May you show the whole list of dependencies for SOAP that are in your pom.xml? – Max Lich Nov 18 '19 at 12:56
  • We changed from that specific dependency to jaxb2-maven-plugin 2.5.0+, which has that dependency among some new others. Check this answer https://stackoverflow.com/a/56972713/1833705 and try the newest version of jaxb2-maven-plugin. – Rafael Renan Pacheco Nov 19 '19 at 14:23
1

You can use Jakarta instead:

<dependency>
    <groupId>jakarta.xml.ws</groupId>
    <artifactId>jakarta.xml.ws-api</artifactId>
    <version>4.0.0</version>
</dependency>
SideX
  • 11
  • 1