Explain Codes LogoExplain Codes Logo

Replacements for Deprecated JPMS Modules with Java EE APIs

java
java-ee
jakarta-ee
maven-coordinates
Alex KataevbyAlex Kataev·Nov 16, 2024
TLDR

To deal with deprecated Java EE JPMS modules, it's suggested to update to Jakarta EE dependencies. Modify your module-info.java with requires jakarta.activation; to continue with functionally equivalent APIs. Include the Jakarta artifacts in your build tool. For instance:

requires jakarta.activation; // Welcome to the future!

For Maven:

<dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> <version>2.0.1</version> <!-- Version 2.0.1, because we love updates, don't we? --> </dependency>

For Gradle:

implementation 'jakarta.activation:jakarta.activation-api:2.0.1' // Easy switch, happier life!

Just synchronize these changes, and you'll be well on your way with Jakarta EE, prolonging your project's health and vigor.

Connecting the dots: Understanding dependencies

With the advent of Java 11, several Java EE modules met their end (moment of silence), which means no upcoming updates or bug fixes. But despair not, for the community stands strong with Jakarta EE, which steps in to provide continued support and compatibility with the new generation of cloud-native applications. Here are some important API replacements:

Depreciated Java EE ModuleJakarta EE Replacement
java.activationjakarta.activation
java.transactionjakarta.transaction
java.xml.bindjakarta.xml.bind
java.xml.wsjakarta.xml.ws
java.xml.ws.annotationjakarta.annotation

You shall not... FAIL: Transitioning smoothly

Switching isn't just about replacing old names with new ones; you must ensure your project’s build path aligns with the new Maven coordinates or Gradle artifacts. And remember, these fresh APIs could possibly bring along tiny changes that might have your existing code doing a double take, so double-check!

Alternative Strategies: Tools, decoding & dealing with issues

Third-party libraries: Your new best friends

Consider making new friends with third-party libraries for any additional functionality or to achieve new performance milestones. For instance, you might find org.glassfish.jaxb:jaxb-runtime useful for JAXB in JDK 9 and up. Just ensure the versions of jaxb-impl and jaxb-api can happily coexist to prevent any code conflicts (we like peace, don't we?).

Runtime dependencies: Knowing when to include

Load up on runtime dependencies only when you're building for JRE 9 or higher. Leaner is better, and it greatly aligns your application with Java's modular approach in its newer releases.

Future-proofing your Java versions

Be ready for the impending removal of deprecated APIs. Remain vigilantly updated about the future plans for prominent libraries. Promote smooth transitions to future Java releases by depending on libraries with a clear roadmap.

Farewell, CORBA APIs

If your application still clings onto the CORBA APIs (i.e., java.corba module), consider third-party maintenance or maybe a complete architectural overhaul (Gasp!). Leaving behind CORBA could potentially favor your project in the long haul.

Turn to Annotations

The Common Annotations API (i.e., javax.annotation-api) can substitute java.xml.ws.annotation. Smooth your transition from @WebServiceRef and similar annotations to their clean-cut Jakarta EE counterparts.

Exploring alternative runtimes

Sometimes, the JVM might not be the perfect runtime, especially when it comes to XML processing. Consider alternative runtimes like GraalVM for enhanced JAXB compatibility or performance boosts, because everyone loves a fast code!