Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mac java 9 gradle ClassNotFoundException: javax.xml.bind.JAXBElement when building

Tags:

java

gradle

I'm trying to build a gradle project on Mac with Java 9, but I'm getting this error:

FAILURE: Build failed with an exception.

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBElement

Java version is:

java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

How do I add JAXB to the classpath? This projects builds on Windows and other computers OK without adding JAXB.

like image 470
Thomas Kessler Avatar asked Nov 19 '22 03:11

Thomas Kessler


1 Answers

You're seeing this because of changes in Java 9. Here's how to solve that: How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9

However, if your project is written for Java 8 (or older), what I would really suggest is letting Gradle know about that in your build.gradle:

...

plugins {
    id 'java'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

...
like image 95
Gorazd Rebolj Avatar answered Jan 10 '23 18:01

Gorazd Rebolj