解决报错java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present

今天在运行程序的时候,一直报“java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present”的错误

百度原因,发现是因为用了jdk12的缘故。因为JAXB-API是java ee的一部分,在jdk12中没有在默认的类路径中。从jdk9开始java引入了模块的概念, 可以使用模块命令–add-modles java.xml.bind引入jaxb-api。也可以选择另一种解决方法,在maven里面加入下面依赖,可以解决这个问题:

<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-impl</artifactId>

  <version>2.3.0</version>

</dependency>

<dependency>

   <groupId>org.glassfish.jaxb</groupId>

   <artifactId>jaxb-runtime</artifactId>

   <version>2.3.0</version> 

</dependency>

<dependency>

  <groupId>javax.activation</groupId>

  <artifactId>activation</artifactId>

  <version>1.1.1</version>

</dependency>

原文地址:https://www.cnblogs.com/lhn9527/p/13894783.html