5

I'm trying to run hibernate-tutorial-hbm module located in basic folder of sample code from Hibernate tutorial. I imported code into Eclipse, added

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

to root pom.xml because I'm using Java 9. When I execute Run as -> Maven test I receive the following error on the console:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.hibernate.tutorial.hbm.NativeApiIllustrationTest
Dec 02, 2017 11:37:26 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
Dec 02, 2017 11:37:26 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.231 sec <<< FAILURE!
testBasicUsage(org.hibernate.tutorial.hbm.NativeApiIllustrationTest)  Time elapsed: 0.203 sec  <<< ERROR!
org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
    at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
    at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:152)
    at org.hibernate.tutorial.hbm.NativeApiIllustrationTest.setUp(NativeApiIllustrationTest.java:49)
    at junit.framework.TestCase.runBare(TestCase.java:139)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:252)
    at junit.framework.TestSuite.run(TestSuite.java:247)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:421)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
    at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:122)
    ... 25 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
    at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
    ... 29 more

Looks like the implementation of JAXB-API is missing. What dependencies should I add to pom.xml to resolve the issue?

user1257
  • 622
  • 1
  • 8
  • 13
  • 1
    what's your surefire configuration? And `mvn clean test` on command line doesn't fail the same way(to confirm the eclipse configuration)? Did you try [this](https://stackoverflow.com/questions/46220810/add-modules-only-on-compilation)? As in `--add-modules java.xml.bind` in surefire configuration? – Naman Dec 02 '17 at 11:19
  • Do take a look at this as well maybe - [java-9-module-java-xml-bind-is-not-accessible-in-eclipse](https://stackoverflow.com/questions/46852065/java-9-module-java-xml-bind-is-not-accessible-in-eclipse) – Naman Dec 02 '17 at 11:30
  • 2
    @nullpointer `--add-modules java.xml.bind` solved the problem. Thanks! However, [this page](https://maven.apache.org/surefire/maven-surefire-plugin/java9.html) says that if JAVA_HOME points to JDK 9 then `--add-modules java.se.ee` is added to JVM arguments. Nonetheless, if you are interested in reputation, you can post an answer about `argLine` and I'll accept it. – user1257 Dec 02 '17 at 12:07
  • 1
    javax.xml.bind:jaxb-api:2.3.0 has the JAXB API. The other artifact that you need is com.sun.xml.bind:jaxb-ri:2.3.0 which is the JAXB implementation. That is why you the CNFE is for com.sun.xml.internal.bind.v2.XXX. More on this topic can be found in JEP 320: http://openjdk.java.net/jeps/320 – Alan Bateman Dec 03 '17 at 09:14
  • [This Answer by bourgesl](https://stackoverflow.com/a/48279048/642706) enabled JAXB 2.3.0 on Java 10 for me. Uses `org.glassfish.jaxb` rather than `com.sun.xml.bind`. – Basil Bourque Jul 17 '18 at 22:34

0 Answers0