Obtain a new instance of a JAXBContext class.
The client application must supply a context path which is a list of colon (':', \u003A) separated java package names that contain schema-derived classes and/or fully qualified JAXB-annotated classes. Schema-derived code is registered with the JAXBContext by the ObjectFactory.class generated per package. Alternatively than being listed in the context path, programmer annotated JAXB mapped classes can be listed in a jaxb.index resource file, format described below. Note that a java package can contain both schema-derived classes and user annotated JAXB classes. Additionally, the java package may contain JAXB package annotations that must be processed. (see JLS, Section 7.4.1 "Named Packages").
Every package listed on the contextPath must meet one or both of the following conditions otherwise a JAXBException will be thrown:
Format for jaxb.index
The file contains a newline-separated list of class names.
Space and tab characters, as well as blank
lines, are ignored. The comment character
is '#' (0x23); on each line all characters following the first comment
character are ignored. The file must be encoded in UTF-8. Classes that
are reachable, as defined in newInstance(Class...)
, from the
listed classes are also registered with JAXBContext.
Constraints on class name occuring in a jaxb.index file are:
To maintain compatibility with JAXB 1.0 schema to java interface/implementation binding, enabled by schema customization <jaxb:globalBindings valueClass="false">, the JAXB provider will ensure that each package on the context path has a jaxb.properties file which contains a value for the javax.xml.bind.context.factory property and that all values resolve to the same provider. This requirement does not apply to JAXB annotated classes.
If there are any global XML element name collisions across the various packages listed on the contextPath, a JAXBException will be thrown.
Mixing generated interface/impl bindings from multiple JAXB Providers in the same context path may result in a JAXBException being thrown.
The steps involved in discovering the JAXB implementation is discussed in the class javadoc.
contextPath | list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes | |
classLoader
| This class loader will be used to locate the implementation classes. |
JAXBException | if an error was encountered while creating the
JAXBContext such as
|
Diagram: JAXB