2

I want to create a little REST application that respond to request with xml. The basic configuration of my application that returns normal strings works fine.

I added the following in my pom.xml in order to add support to xml:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>javax.activation-api</artifactId>
    <version>1.2.0</version>
</dependency>

But I still have the following error when the tomcat server in eclipse loads the application:

java.lang.ClassNotFoundException: javax.xml.bind.JAXBContext

My system configuration:

java --version
openjdk 10.0.1 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10)
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)

eclipse Version: Photon Release (4.8.0)

tomcat 8.5
cedlemo
  • 3,205
  • 3
  • 32
  • 50
  • Sanity check: cleaned? Second sanity check: dependency:tree? – Compass Jul 27 '18 at 20:08
  • @Compass, by cleaned do you ask me if I have cleaned my "build" and redownloaded the dependencies ? If so I did it via eclipse : Maven > update project. For the dependency: tree I don't understand what you mean. – cedlemo Jul 27 '18 at 20:12
  • From command line, or perhaps eclipse, you can run the [dependency:tree](https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html) command to see how your dependencies are being resolved. If there is, for example, a version mismatch, or your dependencies are not being properly resolved, you will be able to see it. – Compass Jul 27 '18 at 20:18
  • @Compass, no version mismatch – cedlemo Jul 27 '18 at 20:41

1 Answers1

2

Since Java 9, JAXB is no longer part of the JDK. This explanation written by Andy Guibert and this migration guide should help you to understand the situation.

Therefore "a quick and dirty solution" is to add --add-modules java.xml.bind to your compile process.

Rene Knop
  • 1,788
  • 3
  • 15
  • 27
  • Is there a way to add `--add-modules` via eclipse directly or should I modify the eclipse.ini ? – cedlemo Jul 27 '18 at 20:41