Identify JAXB Implementation Classes


How to Identify JAXB Implementation Classes?



You can use the following simple Java program,, to Identify JAXB Implementation Classes:

// Copyright (c)
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class JaxbClassInfo {
   public static void main(String[] args) throws Exception {
      JAXBContext c = JAXBContext.newInstance("com.fyicenter.demo");    
      Marshaller m = c.createMarshaller();
    System.out.println("JAXB Implementation Classes:");
    System.out.println("   JAXBContext: "+c.getClass());
    System.out.println("   Marshaller: "+m.getClass());

Compile and run as shown below in the .\src\ folder, where the data type classes were generated by XJC:

fyicenter> cd src

fyicenter> java -cp .:../jaxb-ri/mod/jaxb-api.jar:\
  ../jaxb-ri/mod/javax.activation-api.jar \

JAXB Implementation Classes:
   JAXBContext: class com.sun.xml.bind.v2.runtime.JAXBContextImpl
   Marshaller: class com.sun.xml.bind.v2.runtime.MarshallerImpl

As you can see, the reference implementation of JAXB API has the "com.sun.xml.internal.bind" package name.

But the Java SE implementation of JAXB API bundled in Java 8 has a different package name:

fyicenter> \local\jdk-1.8.0\bin\javac

fyicenter> \local\jdk-1.8.0\bin\java JaxbClassInfo
JAXB Implementation Classes:
   JAXBContext: class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
   Marshaller: class com.sun.xml.internal.bind.v2.runtime.MarshallerImpl


⇒ - Create Object from Data Type Class

⇐ XJC -p Option for Class Package Name

⇑ Examples for JAXB (Java Architecture for XML Binding)

⇑⇑ FAQ for jaxb-*.jar - Java Architecture for XML Binding

2018-05-08, 770👍, 0💬