title: Convert Java object to XML
body: <p>I am trying to convert a Java object inside of a Java library to an XML file. However, I got this problem:</p>
  
  <pre><code>A a = new A();
  
  // initializing for a
  
  JAXBContext jc = JAXBContext.newInstance("libraryA.A");
  
  Marshaller marshaller = jc.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  marshaller.marshal(a, System.out);
  </code></pre>
  
  <p>Then I got this exception:</p>
  
  <pre><code>javax.xml.bind.JAXBException: "libraryA.a" doesnt contain ObjectFactory.class or jaxb.index
      at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:186)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
      at javax.xml.bind.ContextFinder.find(ContextFinder.java:290)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
      at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
  </code></pre>
  
  <p>If I change: <code>JAXBContext jc = JAXBContext.newInstance("libraryA.a");</code> </p>
  
  <p>to:</p>
  
  <pre><code>JAXBContext jc = JAXBContext.newInstance(libraryA.A.class);
  </code></pre>
  
  <p>then I have another exception: </p>
  
  <pre><code>com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
  
  library.A is an interface, and JAXB can't handle interfaces.
      this problem is related to the following location:
          at library.A
  
  library.A does not have a no-arg default constructor.
      this problem is related 
  
  to the following location:
      at library.A
  </code></pre>