1. JAXB 2.0 | |
Q: | Which version of J2SE does JAXB 2.0 require? |
A: | Java SE 6 or higher. |
Q: | Can I run my existing JAXB 1.0.x applications on the JAXB 2.0 runtime? |
A: | This is no longer supported. However, you should be able to deploy
|
Q: | What if I want to port my JAXB 1.0.x application to JAXB 2.0? |
A: | You need to recompile your schema with the newer JAXB 2.0 xjc and modify your application code to work with the new bindings. |
Q: | Are the JAXB runtime API's thread safe? |
A: | The JAXB Specification currently does not address
the thread safety of any of the runtime classes. In the
case of the Oracle JAXB RI, the
For example, suppose you have a multi-thread server
application that processes incoming XML documents by JAXB.
In this case, for the best performance you should have
just one instance of class MyServlet extends HttpServlet { static final JAXBContext context = initContext(); private static JAXBContext initContext() { return JAXBContext.newInstance("....", MyServlet.class.getClassLoader()); } } And each time you need to unmarshal/marshal/validate
a document. Just create a new
public void doGet(HttpServletRequest req, HttpServletResponse resp) { Unmarshaller u = context.createUnmarshaller(); u.unmarshal(...); } This is the simplest safe way to use the JAXB RI from multi-threaded applications. If you really care about the performance, and/or
your application is going to read a lot of small
documents, then creating |
Q: | Why can't I cast the unmarshalled object into the generated type. |
A: | When you invoke
With some applications, things get even more
complicated when the JAXB-generated code can be loaded by
either classloader. In this case,
The solution for both situations is to pass your curent class loader like this: JAXBContext.newInstance("aaa.bbb.ccc", this.getClass().getClassLoader()); In general, if you are writing code that uses JAXB, it is always better to explicitly pass in a class loader, so that your code will work no matter where it is deployed. |
Q: | Which jar files do I need to distribute with my application that uses the JAXB RI? |
A: | For JAXB 2.2.x: $JAXB_HOME/lib/jaxb-api.jar $JAXB_HOME/lib/jaxb-impl.jar |
Q: | How can I cause the |
A: | This functionality is not available from JAXB
directly, but you can configure an Apache Xerces-J
|
Q: | Can I access <xs:any/> as a DOM node? |
A: | In JAXB 2.0, <xs:any/> is handled correctly without any customization.
|
Q: | How do I find out which version of the JAXB RI I'm using? |
A: | Run the following command $ java -jar jaxb-xjc.jar -version Alternatively, each JAXB jar has version information
in its Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.2 Created-By: 1.6.0_29-b11 (Sun Microsystems Inc.) Specification-Title: Java Architecture for XML Binding Specification-Version: 2.2.6 Specification-Vendor: Oracle Corporation Implementation-Title: JAXB Reference Implementation Implementation-Version: 2.2.5-SNAPSHOT Implementation-Vendor: Oracle Corporation Implementation-Vendor-Id: com.sun Extension-Name: com.sun.xml.bind Build-Id: 02/09/2012 01:42PM (hudson) Class-Path: jaxb-api.jar |