java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory

Starts a Java project and hits the below "class not found for com.sun.xml.bind.v2.ContextFactory"? Terminal Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at jakarta.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92) at jakarta.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125) at jakarta.xml.bind.ContextFinder.newInstance(ContextFinder.java:230) … 43 more Solution The com.sun.xml.bind.v2.ContextFactory is under the JAXB APIs; Java 9 deprecated the JAXB, and Java 11 deleted the JAXB completely. To fix …

Read more

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Migrate a Java project to Java 11 and hits the below "class not found error for JAXBException" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException A short history of JAXB on Java The Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is an XML binding framework to convert Java classes to and from XML. The JAXB is part of …

Read more

JAXBException: Implementation of JAXB-API has not been found on module path or classpath

This article shows how to solve the popular JAXB exception Implementation of JAXB-API has not been found on module path or classpath. Table of contents 1. JAXBException: Implementation of JAXB-API has not been found 2. We need a JAXB Implementation 3. JAXB Implementation – Jakarta XML Binding 4. JAXB Implementation – EclipseLink MOXy 4.1 Implementation …

Read more

JAXB hello world example

Jakarta XML Binding (JAXB; formerly Java Architecture for XML Binding) is an XML binding framework to convert Java objects to and from XML. XML Marshalling – Convert Java objects into XML. XML Unmarshalling – Convert XML back into Java Objects. Note This article will focus on Java 11, JAXB 3 and EclipseLink MOXy JAXB RI. …

Read more

XML example with Jersey + JAXB

This tutorial show you how to use JAXB to convert object to XML in Jersey, and return it back to user. 1. Dependency To integrate JAXB with Jersey, no extra dependency is required. Just include “jersey-server.jar” will do. 2. JAXB Annotation Annotate object with JAXB annotation, for conversion later. import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; …

Read more

XML example with RESTEasy + JAXB

RESTEasy, is required JAXB to support XML file. In this tutorial, we show you how to create an “user” object, convert it into XML file, and return it back to the client. 1. RESTEasy + JAXB To use JAXB in RESTEasy, you need to include the “resteasy-jaxb-provider.jar” dependency. File : pom.xml <repositories> <repository> <id>JBoss repository</id> …

Read more

RESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: application/xml

Problem Developing RESTEasy + JAXB provider to support XML, when return it back to client, it prompts following error message : org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.mkyong.rest.User of media type: application/xml at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:500) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) //… Solution To use JAXB in RESTEasy, you need to include “resteasy-jaxb-provider.jar“. <repositories> …

Read more

Spring + JAX-WS : ‘xxx’ is an interface, and JAXB can’t handle interfaces

Problem Integrate Spring + JAX-WS, see web service below : package com.mkyong.user.ws; //imports… @WebService() public class PGUserWS { //DI via Spring private UserBo userBo; public UserBo getUserBo() { return userBo; } public void setUserBo(UserBo userBo) { this.userBo = userBo; } @WebMethod(operationName = "addUser") public boolean addUser(@WebParam(name = "userId") String userId, @WebParam(name = "User") User user) …

Read more