6

I have a simple spring project based on the official guide to consume a web service. This sample seems to be targeting JDK 8 but I want to use the latest LTS, JDK 11.

I have adapted the pom.xml file and added some dependencies which seem to have been removed from the JDK, namely:

        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.2</version>
        </dependency>

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

        <dependency>
            <groupId>com.sun.activation</groupId>
            <artifactId>javax.activation</artifactId>
            <version>1.2.0</version>
        </dependency>

However, I can't seem to start the application, I always get this error:

➜  spring-test git:(master) mvn spring-boot:run
[INFO] Scanning for projects...
...
org.springframework.ws.soap.client.SoapFaultClientException: Implementation of JAXB-API has not been found on module path or classpath.
    at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault (SoapFaultMessageResolver.java:38)
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault (WebServiceTemplate.java:830)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive (WebServiceTemplate.java:624)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive (WebServiceTemplate.java:555)
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive (WebServiceTemplate.java:390)
    at com.example.demo.CountryClient.getCountry (CountryClient.java:21)
    at com.example.demo.DemoApplication.lambda$lookup$0 (DemoApplication.java:24)
    at org.springframework.boot.SpringApplication.callRunner (SpringApplication.java:781)
    at org.springframework.boot.SpringApplication.callRunners (SpringApplication.java:765)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:319)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1215)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:1204)
    at com.example.demo.DemoApplication.main (DemoApplication.java:13)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:543)
    at java.lang.Thread.run (Thread.java:834)

Although there are at least two questions (this and this) related to this topic, I've tried all combinations of versions that I could find in those posts and I still have the same error.

The specific JDK+maven version I'm using is:

Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T16:06:16+01:00)
Maven home: /usr/local/Cellar/maven/3.6.2/libexec
Java version: 11.0.4, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

And the code for my test is here.

André Cruz
  • 500
  • 1
  • 5
  • 15
  • Does this answer your question? [Replacements for deprecated JPMS modules with Java EE APIs](https://stackoverflow.com/questions/48204141/replacements-for-deprecated-jpms-modules-with-java-ee-apis) – 9ilsdx 9rvj 0lo Jun 07 '21 at 11:53

2 Answers2

14

Take a look at this answer and check if it may help you. We have a couple of projects using Java 11 with Spring WS and everything is working just fine. Also make sure that your pom.xml is targeting Java 11:

<properties>
    <java.version>11</java.version>
    <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>

Regarding the missing classes, we had to add the following dependency, and nothing else:

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>
Rafael Renan Pacheco
  • 2,138
  • 21
  • 22
  • My `pom.xml` is in the repository ([here](https://github.com/edevil/spring-test/blob/master/pom.xml)), I am targeting jdk 11 and have the dependency that you mentioned. – André Cruz Oct 07 '19 at 14:59
  • 1
    Instead of `maven-jaxb2-plugin` try to use `jaxb2-maven-plugin` 2.5+, which was mentioned on that answer. Only 3 months ago they fixed all Java 11 issues regarding those classes. The plugin you are using had the last update on May 2018, which most likely doesn't fix those Java 11 issues. – Rafael Renan Pacheco Oct 07 '19 at 18:41
  • It turns out the error I was receiving was from the server, which did not have the jaxb dependency. – André Cruz Oct 29 '19 at 09:59
  • 1
    @AndréCruz THANK YOU! I tried run the server and the client ( https://spring.io/guides/gs/consuming-web-service/ and https://spring.io/guides/gs/producing-web-service/ ) Thus I run into the same problem. I try out to run SERVER with java8: ./gradlew clean assemble bootRun -Dorg.gradle.java.home=/opt/java/java8 and IT WORKS!!! Can you add the answer in your question? – wakedeer May 27 '21 at 17:00
2

we must add the following dependence

<dependency>
    <groupId>javax.xml</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
</dependency>

insted :

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0.1</version>
</dependency>

it is a problem for all version of the jdk 11 even on amazone correto

Omar Amaoun
  • 526
  • 1
  • 3
  • 20