Home  >  Forum  >  Spring
Post New Query

[SOLVED-JAVA 9] Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException



Asked on November 10, 2017
Hi, I am creating application using Spring and Hibernate. I am using Java 9 and Spring 5.0.1. While starting server, there is following error in console.

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:208)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:163)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:51)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:358)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:373)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1763)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1700)
... 25 common frames omitted



Replied on November 11, 2017
JDK 9 has done some changes for java.xml.bind and other java EE modules. Let us understand.

1.

JDK 9 has deprecated java.xml.bind module and has removed from default classpath.
@Deprecated(since="9", forRemoval=true)

Module java.xml.bind
Deprecated, for removal: This API element is subject to removal in a future version.

https://docs.oracle.com/javase/9/docs/api/java.xml.bind-summary.html

Java has made plan to remove the Java EE and CORBA modules from Java SE and the JDK after JDK 9 versions. In Java 9 they have only deprecated and have removed it from classpath.

2.

javax.xml.bind is sub package of Module java.xml.bind

So Module javax.xml.bind will not be available on classpath by default in JAVA 9.

Solution:

1. Use --add-modules to add module in classpath.

As Java has not yet removed from module from java 9. Java has only deprecated and does not add javax.xml.bind module on classpath by default.

So if we want to add javax.xml.bind on classpath we can add using following command.


--add-modules java.xml.bind

2. We can use Maven and Gradle to include javax.xml.bind in our project.

Maven

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

Gradle

compile 'javax.xml.bind:jaxb-api:2.3.0'



Find the reference link

http://openjdk.java.net/jeps/8189188




Replied on November 11, 2017
Thanks Mohit. It worked.

Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us