Keywords: Java 11 | JAX-WS | Jakarta EE | SOAP | Modularization
Abstract: This paper provides an in-depth examination of the root causes behind the missing javax.xml.soap package in Java 11, detailing the evolution of JAX-WS modules from Java 8 to Java 11. By systematically analyzing the removal of Java EE modules, it offers complete migration strategies from traditional JAX-WS to modern Jakarta EE, including Maven dependency configurations, code modification examples, and version compatibility explanations. The article also discusses the fundamental differences between HTML tags like <br> and character \n, helping developers fully understand and resolve this common compatibility issue.
In Java development, many developers encounter compilation errors when upgrading from Java 8 to Java 11: package javax.xml.soap does not exist. The root cause of this issue lies in significant changes to the Java Platform Module System, particularly the removal of Java EE-related modules. This article will provide a thorough analysis of the technical background behind these changes and offer detailed solutions.
Problem Background and Root Causes
When developers attempt to create messages using SOAP (Simple Object Access Protocol), they typically import the javax.xml.soap package. In Java 8, this package exists as part of the Java standard library, but it cannot be found in Java 11. This is because Java 11 removed Java EE modules according to JEP 320.
Specifically, the evolution of the java.xml.ws module (containing JAX-WS, SAAJ, and Web Services Metadata) is as follows:
- Java 8: Fully supported
- Java 9: Marked as deprecated
- Java 10: Continued deprecation
- Java 11: Completely removed
This change reflects Java platform's transition to a modular architecture and Oracle's strategic decision to transfer Java EE technologies to the Eclipse Foundation. Developers need to understand that the javax.xml.soap package now belongs to the Jakarta EE specification, not the Java SE standard library.
Traditional Solution: Using JAX-WS RI
For projects requiring backward compatibility, the issue can be resolved by adding JAX-WS Reference Implementation (RI) dependencies through Maven. Here's a basic dependency configuration example:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>
This dependency includes the complete JAX-WS technology stack, allowing developers to continue using classes from the javax.xml.soap package. For example, code for creating SOAP messages can remain unchanged:
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
public class SoapExample {
public static void main(String[] args) throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();
// Further message processing
}
}
Modern Migration Approach: Jakarta EE 8
With the release of Jakarta EE 8 (March 2020), it's recommended to use the new Jakarta namespace. This requires modifying both dependencies and import statements:
<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>
Imports in code need to change from javax.xml.soap to jakarta.xml.soap:
import jakarta.xml.soap.MessageFactory;
import jakarta.xml.soap.SOAPMessage;
public class JakartaSoapExample {
public static void main(String[] args) throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();
// Process messages using Jakarta API
}
}
Latest Technology Stack: Jakarta EE 9 and 10
Jakarta EE 9 (November 2020) and Jakarta EE 10 (June 2022) provide updated specification versions. Jakarta EE 10's XML Web Services 4.0 specification requires Java SE 11 or newer, making it suitable for modern Java projects.
Jakarta EE 10 dependency configuration is as follows:
<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>
Developers should note that migration from javax to jakarta involves more than just package name changes; it also includes subtle API adjustments. For instance, some methods may have been deprecated or replaced, so consulting official documentation for detailed adaptation is recommended.
Technical Details and Best Practices
When handling HTML content, developers need to distinguish between text descriptions and actual tags. For example, when discussing string processing, the <br> tag as text content requires escaping, while actual line break tags do not. This distinction is crucial for generating correct XML or HTML output.
Here's a code example demonstrating proper handling of text containing special characters:
public class XmlProcessor {
public static String escapeXml(String input) {
return input
.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("\"", """)
.replace("'", "'");
}
public static void main(String[] args) {
String text = "The article also discusses the fundamental differences between HTML tags <br> and character \n";
System.out.println(escapeXml(text));
// Output: The article also discusses the fundamental differences between HTML tags <br> and character \n
}
}
When choosing a solution, developers should consider the following factors:
- Project Requirements: If integration with legacy systems is needed, JAX-WS RI might be appropriate; for new projects, Jakarta EE is recommended.
- Java Version: Ensure dependency versions are compatible with the Java runtime.
- Maintainability: Jakarta EE, as an active open-source project, offers better long-term support.
By understanding the evolution of Java's module system and adopting appropriate dependency management strategies, developers can effectively resolve the missing javax.xml.soap package issue and build robust, maintainable web service applications.