47

I'm trying to create a simple message using SOAP:

MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();

When I build the project with Java 8 it's fine, but building it with Java 11 fails with a compilation error:

package javax.xml.soap does not exist

How do I fix the issue?

Boris
  • 22,667
  • 16
  • 50
  • 71

1 Answers1

117

JAX-WS removed from Java 11

JAX-WS is no longer bundled with Java 11.

According to the release notes, Java 11 removed the Java EE modules:

java.xml.ws (JAX-WS, plus the related technologies SAAJ and Web Services Metadata) - REMOVED
  • Java 8 - OK
  • Java 9 - DEPRECATED
  • Java 10 - DEPRECATED
  • Java 11 - REMOVED

See JEP 320 for more info.

You can fix the issue by using alternate versions of the Java EE technologies. Simply add a com.sun.xml.ws : jaxws-ri Maven artifact that contains the technologies you need:

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

Jakarta EE 8 update (Mar 2020)

Instead of using old JAX-WS module you can fix the issue by using Jakarta XML Web Services from Jakarta EE 8:

<dependency>
  <groupId>jakarta.xml.ws</groupId>
  <artifactId>jakarta.xml.ws-api</artifactId>
  <version>2.3.3</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-rt</artifactId>
  <version>2.3.3</version>
  <scope>runtime</scope>
</dependency>

Jakarta EE 9 update (Nov 2020)

Use latest release of Jakarta XML Web Services 3.0:

<dependency>
  <groupId>jakarta.xml.ws</groupId>
  <artifactId>jakarta.xml.ws-api</artifactId>
  <version>3.0.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-rt</artifactId>
  <version>3.0.0</version>
  <scope>runtime</scope>
</dependency>

Note: change javax.* imports to jakarta.*

Jakarta EE 10 update (Jun 2022)

Use latest release of Jakarta XML Web Services 4.0 (requires Java SE 11 or newer):

<dependency>
  <groupId>jakarta.xml.ws</groupId>
  <artifactId>jakarta.xml.ws-api</artifactId>
  <version>4.0.0</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-rt</artifactId>
  <version>4.0.0</version>
  <scope>runtime</scope>
</dependency>
Boris
  • 22,667
  • 16
  • 50
  • 71
  • 10
    Be aware, the above `jaxws-ri` dependency includes a lot of jar files, you probably don't need all of them. – holmis83 Aug 07 '19 at 14:33
  • Hi, I´ve tried your approach but there are some missing (or wrong) dependencies - I´ve asked on my own question, without answer so far. https://stackoverflow.com/questions/60395722/migrating-from-java-8-to-11-jaxws-rt – Johnczek Feb 28 '20 at 14:30
  • 2
    @holmis83, I have updated the answer with Jakarta EE 8, which is free of the issue you pointed out. – Boris Mar 25 '20 at 15:51
  • @holmis83 - I just upgraded my old school JDK 7 app => JDK 11 using the jakarta dependency. Thank you! Saved me a lot of hair pulling! –  Apr 15 '20 at 18:16
  • I run Redhat OpenJDK 8 for windows and javax.xml packages are gone. – Leos Literak Jun 12 '20 at 09:48
  • @LeosLiterak can you provide a link to the JDK? – Boris Jun 12 '20 at 12:28
  • I was wrong. Upgraded Idea used the bundled JDK 11. – Leos Literak Jun 12 '20 at 18:05