Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run JOOQ GenerationTool with Java 11 (NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema)

Tags:

java

java-11

jooq

I attempted to run the code gen with this command line as described in the documentation here:

java -classpath "jooq-3.12.3.jar;jooq-meta-3.12.3.jar;jooq-codegen-3.12.3.jar;mysql-connector-java-5.1.18-bin.jar;." org.jooq.codegen.GenerationTool library.xml

I get the following error:

Jan 10, 2020 5:10:45 PM org.jooq.tools.JooqLogger info
INFO: Initialising properties : library.xml
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at org.jooq.util.jaxb.tools.MiniJAXB.getNamespace(MiniJAXB.java:389)
...

I'm using Java 11:

openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.5+10, mixed mode)

What am I missing? PS. I'm very new to the world of Java...

like image 594
Eli Pulsifer Avatar asked Jan 10 '20 23:01

Eli Pulsifer


2 Answers

The problem is connected with removal of JAXB api as it was considered a part of JAVA EE API, thus removed form JDK since Java 9 (see this question for details).

You can solve your problem by adding jaxb-api jar to your classpath :

java -classpath "jooq-3.12.3.jar;jooq-meta-3.12.3.jar;jooq-codegen-3.12.3.jar;reactive-streams-1.0.2.jar;mysql-connector-java-5.0.7.jar;jaxb-api-2.3.1.jar" org.jooq.codegen.GenerationTool library.xml

Notice that I also had to add reactive-streams-1.0.2 jar to the classpath (as the tutorial mentions).

And change the MySQL driver jar to your jar in the command I pasted. So the final command in your case will be :

java -classpath "jooq-3.12.3.jar;jooq-meta-3.12.3.jar;jooq-codegen-3.12.3.jar;reactive-streams-1.0.2.jar;mysql-connector-java-5.1.18-bin.jar;jaxb-api-2.3.1.jar" org.jooq.codegen.GenerationTool library.xml
like image 157
Michał Krzywański Avatar answered Sep 17 '22 16:09

Michał Krzywański


The JAXB API is an unfortunate external dependency of jOOQ, which we've been trying to remove step by step in recent versions. We've already removed the JAXB implementation dependency, but the API, we still depend on in various parts of jOOQ.

It should be possible to use jOOQ and jOOQ's code generator without explicitly putting the JAXB API on the classpath also in JDK 11+. I've created an issue to resolve this particular problem: https://github.com/jOOQ/jOOQ/issues/9723

The MiniJAXB class is already a workaround to avoid depending on the JAXB implementation. jOOQ should also avoid depending on the JAXB API, in the future.

For the time being, michalk's solution is the only viable one if you do not want to use Maven or Gradle to resolve your transitive dependencies for you.

like image 21
Lukas Eder Avatar answered Sep 19 '22 16:09

Lukas Eder