(47条消息) java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException的解决方案

日志信息:

  1. java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
  2. at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
  3. at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
  4. at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:179)
  5. at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
  6. at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
  7. at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
  8. at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
  9. at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
  10. at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
  11. at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
  12. at com.heima.test.JpaTest.testSave(JpaTest.java:27)
  13. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  14. at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  15. at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  16. at java.base/java.lang.reflect.Method.invoke(Method.java:564)
  17. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  18. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  19. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  20. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  21. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  22. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  23. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  24. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  25. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  26. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  27. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  28. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  29. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  30. at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  31. at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  32. at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  33. at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  34. at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  35. Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
  36. at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
  37. at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
  38. at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
  39. ... 33 more

原因:

           我使用JDK版本是JDK9.0,缺少JAXB API的jar包。JAXB API是java EE 的API,因此在java SE 9.0 中不再包含这个 Jar 包。 java 9 中引入了模块的概念,默认情况下,Java SE中将不再包含java EE 的Jar包 
而在 java 6/7 / 8 时关于这个API 都是捆绑在一起的

 解决方案:

一、降低JDK版本

二、导入相关的jar包或者maven依赖

  1. <dependency>
  2. <groupId>javax.xml.bind</groupId>
  3. <artifactId>jaxb-api</artifactId>
  4. <version>2.3.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.sun.xml.bind</groupId>
  8. <artifactId>jaxb-impl</artifactId>
  9. <version>2.3.0</version>
  10. </dependency>
  11. <dependency>
  12. <groupId>com.sun.xml.bind</groupId>
  13. <artifactId>jaxb-core</artifactId>
  14. <version>2.3.0</version>
  15. </dependency>
  16. <dependency>
  17. <groupId>javax.activation</groupId>
  18. <artifactId>activation</artifactId>
  19. <version>1.1.1</version>
  20. </dependency>

 

 

(0)

相关推荐