Java 9 deprecated six modules that contain Java EE APIs and they are going to be removed soon:
java.activation with javax.activation package
java.corba with javax.activity, javax.rmi, javax.rmi.CORBA, and org.omg.* packages
java.transaction with javax.transaction package
java.xml.bind with all javax.xml.bind.* packages
java.xml.ws with javax.jws, javax.jws.soap, javax.xml.soap, and all javax.xml.ws.* packages
java.xml.ws.annotation with javax.annotation package
Which maintained third-party artifacts provide those APIs? It doesn't matter how well they provide those APIs or which other features they have to offer - all that matters is, are they a drop-in replacement for these modules/packages?
To make it easier to collect knoweldge, I answered with what I know so far and made the answer a community wiki. I hope people will extend it instead of writing their own answers.
Before you vote to close:
Yes, there are already some questions on individual modules and an answer to this question would of course duplicate that information. But AFAIK there is no single point to learn about all of these, which I think has a lot of value.
Questions asking for library recommendations are usually considered off-topic, because "they tend to attract opinionated answers and spam", but I don't think that applies here. The set of valid libraries is clearly delineated: They have to implement a specific standard. Beyond that nothing else matters, so I don't see much risk for opinion and spam.
Instead of using the deprecated Java EE modules, use the following artifacts.
JAF (java.activation)
JavaBeans Activation Framework (now Jakarta Activation) is a standalone technology (available on Maven Central):
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<version>1.2.2</version>
</dependency>
(Source)
CORBA (java.corba)
From JEP 320:
There will not be a standalone version of CORBA unless third parties take over maintenance of the CORBA APIs, ORB implementation, CosNaming provider, etc. Third party maintenance is possible because the Java SE Platform endorses independent implementations of CORBA. In contrast, the API for RMI-IIOP is defined and implemented solely within Java SE. There will not be a standalone version of RMI-IIOP unless a dedicated JSR is started to maintain it, or stewardship of the API is taken over by the Eclipse Foundation (the transition of stewardship of Java EE from the JCP to the Eclipse Foundation includes GlassFish and its implementation of CORBA and RMI-IIOP).
JTA (java.transaction)
Stand alone version:
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>1.3.3</version>
</dependency>
(Source)
JAXB (java.xml.bind)
Since Java EE was rebranded to Jakarta EE, JAXB is now provided by new artifacts:
<!-- API -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<scope>runtime</scope>
</dependency>
<!-- Alternative runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
<scope>runtime</scope>
</dependency>
JAXB Reference Implementation page.
The alternative runtime was brought up by Abhijit Sarkar.
schemagen and xjc can be downloaded from there too as part of a standalone JAXB distribution.
See also linked answer.
JAX-WS (java.xml.ws)
Reference implementation:
<!-- API -->
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.3</version>
</dependency>
Standalone distribution download (contains wsgen and wsimport).
Common Annotations (java.xml.ws.annotation)
Java Commons Annotations (available on Maven Central):
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
(Source)
JAXB (java.xml.bind) for JDK9
Working perfectly in my desktop applications on jdk9/10 EA
<properties>
<jaxb-api.version>2.3.0</jaxb-api.version>
</properties>
<!-- JAXB 2.3.0 for jdk9+ -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<!-- JAXB needs javax.activation module (jdk9) -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
I needed to replace JAX-WS (java.xml.ws) and JAXB (java.xml.bind) for my Spring Boot 2 based application and ended up with these JARs (Gradle build):
// replacements for deprecated JDK module java.xml.ws
runtimeOnly 'javax.xml.ws:jaxws-api:2.3.0' // javax.xml.ws.* classes
runtimeOnly 'javax.jws:jsr181-api:1.0-MR1' // for javax.jws.* classes
// replacement for deprecated JDK module java.xml.bind
runtimeOnly 'javax.xml.bind:jaxb-api'
runtimeOnly 'org.glassfish.jaxb:jaxb-runtime:2.3.0.1'
runtimeOnly 'org.glassfish:javax.json:1.1.2'
runtimeOnly 'org.eclipse:yasson:1.0.1'
(You may need compile or other scope, runtimeOnly was enough for us.)
I noticed that https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core is described as "Old" and using this answer went for org.glassfish based stuff that brought in org.eclipse.yasson as well.
Now it's really messy situation, it works, but how should anyone be sure it's the best replacement, right?
It seems that jaxws-ri depends transitively from commonj.sdo:commonj.sdo:jar:2.1.1.v201112051852 which apparently can be found from repository http://download.eclipse.org/rt/eclipselink/maven.repo
I'm using jdk 11 + ant + ivy in my spring mvc project.
I was getting error "package javax.jws does not exist" so I added javax.jws-api-1.1.jar to classpath and it worked!
Just download the jar from https://repo1.maven.org/maven2/javax/jws/javax.jws-api/1.1/javax.jws-api-1.1.jar
And add it to your classpath in your build.xml
Alternatively add it to your pom.xml:
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
Just a minor variation (improvement) on the above answers --- exemplified here for JAXB only. One can add the dependencies with the runtime scope and only if this is effectively needed (i.e. when building for running in a JRE with version >= 9 --- here v11 is exemplified):
<profile>
<id>when-on-jdk-11</id>
<activation>
<jdk>11</jdk>
</activation>
<properties>
<!-- missing artefacts version properties -->
<jaxb-api.version>2.3.1</jaxb-api.version>
<jaxb-impl.version>2.3.2</jaxb-impl.version> <!-- one might let it the same with the jaxb-api.version -->
</properties>
<dependencies>
<!-- runtime dependencies to avoid JAXB related CNF exceptions when running on Java 11 (e.g.: ClassNotFoundException: javax.xml.bind.annotation.XmlType) -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-impl.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
If you have this issue in Talend (7.x for example), you can add in the Default POM.xml of the project:
<dependencies>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
Tested with :
AdoptJDK 8.0.275.1-hotspot : OK
AdoptJDK 11.0.9.101-hotspot : OK
AdoptJDK 15.0.1.9-hotspot : KO (but It is another issue: Incompatible conditional operand types Exception and TDieException)
Zulu-8.50.0.1017: OK
Zulu-11.43.1015 : OK
I have experimented with most of the suggestions described above using JDK 11.0.3 and have been not been successful. The only solution that I eventually found to work is the following. Perhaps there are other options that also work but it appears that the selection of version is critical. For example, changing com.sun.xml.ws:rt to 2.3.2 causes module javax.jws to no long be available.
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.1</version>
</dependency>
If you have the same problem add the below dependency to pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.3</version>
</dependency>
Then use JAVA 8 as an alternate JRE. For further details refer to this video, which worked for me.
I found the easiest path to get around the JAXB parts of these issues was to use dependency management in my root pom or in my bom:
<project ...>
<dependencyManagement>
<dependencies>
<!-- ... -->
<!-- Gone from jvm in java11 -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-ri</artifactId>
<version>2.4.0-b180830.0438</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- ... -->
</dependencies>
</dependencyManagement>
</project>
And in the modules that fail compilation on jdk11:
<!-- ... -->
<dependencies>
<!-- Gone from jvm in java11 -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>runtime</scope>
</dependency>
<!-- ... -->
</dependencies>
<!-- ... -->
Also, updating the version of org.jvnet.jaxb2.maven2:maven-jaxb2-plugin to 0.14.0 solved all the jaxb generation issues for me.
It's indeed a real pain still going through this as of 2022!
I tried many above suggestions, but only could only get it to work with below dependencies.
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.25.0-GA</version>
</dependency>
Note: Don't be tempted to update the dependencies, just leave it that way, and it works for me.
Related
I'm trying to use PMML4S to make predictions from an imported model from sklearn. I have the model in an xml file that I am trying to load into java using pmml4s. I am trying to follow this. However, I am having issues getting it to work: specifically, "Package 'org.pmml4s.model' is declared in module with an invalid name ('pmml4s.2.10')" . I am using IntelliJ as my IDE. Please let me know if I can provide other information/code. Any help is appreciated!
Error is here:
import org.pmml4s.model.Model;
Dependencies:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>18.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>18.0.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.pmml4s</groupId>
<artifactId>pmml4s_2.10</artifactId>
<version>0.9.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>doctor</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
</dependencies>
You used java 9 modules in your project and imported a library which was not converted to java 9 modules. Thus Java treats this library as an automatic module and derives module name from jar name. The jar name happens to be illegal.
See:
What is an automatic module?
You have 2 options:
Option 1: Dont use java9 modules
See:
Is there any need to switch to modules when migrating to Java 9 or later?
Option 2: Sanitize jar name
See:
Unable to derive module descriptor for auto generated module names in Java 9?
Scala Suffix Maven plugin looks like a tool designed precisely to solve your problem
Note that you need to require the automatic module in this approach:
How to use 3rd party library in Java9 module?
I'm getting the following error in my tests java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.adapters.XmlAdapter when migration to Jakarta EE libraries, what is needed to fix it?
The JAXB classes has moved to jakarta namespace instead of javax as part of the Java EE to Jakarta EE transition.
You should ad the following dependencies to your classpath.
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>3.0.0</version>
</dependency>
We are migrating to openjdk 11 from jdk 8. Some of our projects that uses soap to call third party apis are failing with error:
java.lang.NoClassDefFoundError: javax/xml/ws/handler/soap/SOAPHandler
After doing some research, I tried by adding dependencies :
[
references:
How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9
Replacements for deprecated JPMS modules with Java EE APIs
]
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.3.5</version>
</dependency>
Did not work. may I get an idea on the alternatives?
Include jaxws-api in your dependencies:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
The javax APIs were transitioned to Jakarta, so in 2020 the proper dependency is the following:
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>2.3.3</version>
</dependency>
Here's an article summarizing what happened:
Java Magazine - Transition from Java EE to Jakarta EE
And here's a very useful table with mappings between the old artifacts and the new one.
Since this is the first result on google, my issue was due to having a jar, that required javax.xml.ws classes, on the Tomcat common folder /usr/local/tomcat/lib.
The Tomcat classloader hierarchy is
Bootstrap
|
System
|
Common
/ \
Webapp1 Webapp2 ...
On Java 8 the common classloader can load these classes since they are on Java JRE itself, but on Java 11, the javax.xml.ws classes are on Webapp1, and the Tomcat common classloader can not load these.
For me, the solution was to no longer deploy the jar into the Tomcat common lib folder.
Historically, I always used the following JAXB RI artifacts in my Maven projects:
com.sun.xml.bind:jaxb-impl - Runtime
com.sun.xml.bind:jaxb-xjc - Schema compiler
com.sun.xml.bind:jaxb-jxc - Schema generator
Since approximately version 2.2.10* these artifacts are now described as "old":
com.sun.xml.bind:jaxb-impl
Old JAXB Runtime module.
So it looks like these artifacts are now obsolete.
The question is:
Which artifacts should be used instead?
After clarification with Oracle, the following artifacts should be used:
Runtime
If you want to unmarshal XML to Java objects or marshal Java objects as XML:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>...</version>
</dependency>
Schema compiler (XJC)
If you have an XML Schema and want to generate the Java code out of it:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>...</version>
</dependency>
Schema generator (JXC/schemagen)
If you have Java classes with JAXB annotations and want to generate a XML Schema based on them:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>...</version>
</dependency>
The two latter artifacts (org.glassfish.jaxb:jaxb-xjc and org.glassfish.jaxb:jaxb-jxc) are wrapped by Maven plugins so you normally would not need them in the runtime.
Eclipse usage
If your Maven projects somehow don't get the full classpath, turn on debug output and check the Maven console. You might be seeing the following error message there:
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} #
This is due to the following problem:
Maven not picking JAVA_HOME correctly
The solution by #rustyx is to add -vm option to the eclipse.ini:
-vm
<PATH_TO_JDK>\jre\bin\javaw.exe
For the latest JAXB 2 version 2.3.3 according to the Eclipse Implementation of JAXB these are the Maven coordinates for Eclipse implementation of JAXB artifacts:
<!-- API classes for Jakarta XML Binding. Required to compile against Jakarta XML Binding. -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Contains the main runtime used for serialization and deserialization java objects to/from xml. -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.6</version>
</dependency>
<!-- Tool to generate Jakarta XML Binding java sources from XML representation. -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.6</version>
</dependency>
<!-- Tool to generate XML schema from Jakarta XML Binding java sources. -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>2.3.6</version>
</dependency>
Also, the documentation says that
In general com.sun.xml.bind artifacts are supposed to be used instead.
The maven coordinates for them are:
<!-- API classes for Jakarta XML Binding. Required to compile against Jakarta XML Binding. -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- RI Implementation of JAXB runtime jar. -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.6</version>
</dependency>
<!-- Class generation tool jar. -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.3.6</version>
</dependency>
<!-- Schema generation tool jar. -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>2.3.6</version>
</dependency>
EDIT: The documentation for the JAXB version 2.3.3 has been removed already. Here's the link to the same section for JAXB 2.3.7
I'm dealing with the development of a Java EE project that involves several tools such as jBPM, Hibernate, Resteasy, ect.
In order to manage dependencies, I'm using Maven: my pom.xml is available here.
Now, I'd like to use inside that project QueryDSL 3.4.3 that depends on Google Guava 14.0.1: unfortunately, something imports as dependency Google Collections 1.0 that generates a conflict with Google Guava 14.0.1.
Is it possible to understand where Google Collections is from?
Is there a way to resolve this issue safety? (Now, I'm just removing Google Collections's jar from the deployment folder)
Update
By using the command mvn dependency:tree, I found that Google Collections 1.0 comes from:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
</dependency>
Now, I've just to understand if it will work well also by excluding google-collections.
See also: http://grepcode.com/.../shrinkwrap-resolver-impl-maven/2.1.1/
As said, Google Collection dependency comes from shrinkwrap-resolver-impl-maven.
I resolved that issue by editing the pom.xml as follows:
<!-- ShrinkWrap Maven Resolver for Arquillian Tests -->
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
Then:
<!-- Arquillian profiles -->
<profiles>
<!-- Arquillian test profile managed by JBoss AS 7 -->
<profile>
<id>arquillian-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>google-collections</artifactId>
<groupId>com.google.collections</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</profile>
</profiles>
Now, it works fine.