Java EE APIs
JPMS modules
deprecated modules
Java programming
module replacements

Replacements for deprecated JPMS modules with Java EE APIs

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

With the introduction of the Java Platform Module System (JPMS) in Java 9, several Java EE (now Jakarta EE) APIs that were part of the standard library in previous Java versions were marked as deprecated or removed. This shift encouraged developers to rely on standalone versions of these APIs and aim for a more modular approach. As these deprecated modules are phased out, alternatives must be integrated into Java applications. This article will explore the replacements for these deprecated modules, providing insights and guidance on transitioning to new APIs.

Understanding Deprecated JPMS Modules

The JPMS was designed to introduce modularity to the Java platform, aiming to provide better encapsulation and dependency management. However, this also meant that some APIs, which were previously bundled with the JDK, were either moved to different modules or removed, necessitating the adoption of external libraries or newer APIs. Major Java EE APIs such as JAXB (Java API for XML Binding), JAX-WS (Java API for XML Web Services), and JAX-RS (Java API for RESTful Web Services) were affected.

Transitioning from Deprecated APIs

JAXB (Java API for XML Binding)

JAXB is used to convert Java objects to/from XML. It was bundled with JDK 8 but is no longer contained in JDK 11 and above. To continue using JAXB:

  • Add JAXB as a Dependency: Integrate an external JAXB implementation such as the one from the Eclipse project (EclipseLink MOXy).
  • Example Dependency in Maven:
xml
1  <dependency>
2      <groupId>org.eclipse.persistence</groupId>
3      <artifactId>org.eclipse.persistence.moxy</artifactId>
4      <version>2.7.4</version>
5  </dependency>

JAX-WS (Java API for XML Web Services)

JAX-WS facilitates SOAP web services. Similar to JAXB, for Java 11 onwards, it must be included manually:

  • Add JAX-WS as a Dependency: Use libraries such as Apache CXF or Metro.
  • Example Dependency in Maven using Metro:
xml
1  <dependency>
2      <groupId>org.glassfish.metro</groupId>
3      <artifactId>webservices-rt</artifactId>
4      <version>2.4.3</version>
5  </dependency>

JAX-RS (Java API for RESTful Web Services)

For RESTful services, JAX-RS has not been included in the JDK since Java 11:

  • Using Jakarta RESTful Web Services: Adopt Jakarta REST API, formerly known as JAX-RS.
  • Dependency Example for Jersey, a popular JAX-RS implementation:
xml
1  <dependency>
2      <groupId>org.glassfish.jersey.core</groupId>
3      <artifactId>jersey-server</artifactId>
4      <version>2.32</version>
5  </dependency>

Summary Table

Here is a quick reference to the replacements for common Java EE APIs:

Java EE APIUse CaseRecommended ReplacementExample Dependency
JAXBXML BindingEclipseLink MOXyorg.eclipse.persistence:org.eclipse.persistence.moxy:2.7.4
JAX-WSSOAP ServicesMetroorg.glassfish.metro:webservices-rt:2.4.3
JAX-RSRESTful ServicesJerseyorg.glassfish.jersey.core:jersey-server:2.32

Implementing the New Dependencies

When introducing these new dependencies into a project, it's crucial to remove or exclude any old or conflicting transitive dependencies that might be included in other libraries. Use tools such as Maven's <exclusion> tag to manage these.

Challenges and Considerations

  • Testing: Ensure that replacing deprecated modules with new ones does not break existing functionality.
  • Performance and Compatibility: New libraries might have performance implications or compatibility issues with older Java versions; thorough testing is recommended.
  • Learning Curve: Developers may need time to familiarize themselves with new APIs and libraries.

Conclusion

The transition from deprecated Java EE modules in JPMS to standalone libraries or alternative APIs ensures better modularity and maintainability of Java applications. It does require some initial effort and adjustment but ultimately aligns Java projects with modern software architecture standards, promoting cleaner, more modular codebases. By carefully selecting suitable replacements and updating project dependencies, developers can effectively manage this transition.


Course illustration
Course illustration

All Rights Reserved.