I've spent the day debugging an issue with JAXB getting namespaces wrong or missing (possibly related to Marshaller.JAXB_FRAGMENT, but that's not the point here).
I found the problem occurs with JAXB RI 2.1.10 in my endorsed dir.
It is fixed if I use JAXB RI 2.2.4 or 2.2.6
Here is what is really confusing (and what made it take so long).
The problem occurs on Linux with the JAXB in the following JDK (ie nothing in endorsed):
$ java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu2)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)
$ xjc -version
xjc 2.2.4
but it should work fine, if this java really uses the same JAXB as RI 2.2.4 !!
Please note that the issue I was debugging has nothing to do with xjc; I'm just using that command to try to ascertain what version of JAXB I'm using.
Similarly, I can't reproduce the issue on Windows with Java 1.6.0_27 (and nothing in my endorsed dir), which reports:
C:\Program Files\Java\jdk1.6.0_27\bin>java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)
C:\Program Files\Java\jdk1.6.0_27\bin>xjc -version
xjc version "JAXB 2.1.10 in JDK 6"
JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build JAXB 2.1.10 in JDK 6)
and yet if I put 2.1.10 RI in my endorsed dir, the problem occurs. It should occur with 1.6.0_27, if that really uses the equivalent of JAXB RI 2.1.10.
It seems to me that the problem I'm experiencing has been fixed in the reference implementation somewhere after 2.1.10 and before 2.2.4, but that neither of the 2 VM's above actually use the JAXB version they claim to. Or possibly they use the xjc they claim, but not what is in jaxb-api.jar and jaxb-impl.jar (I know there is a difference in the namespace prefix mapper property and in the package names, but that won't be causing this problem).
I've done these experiments on Win 7 and Ubuntu, in tomcat (no eclipse), and in eclipse (no tomcat), so I'm pretty confident I'm explaining my findings correctly.
Can anyone provide any insight into what is happening?
If I'm right, does anyone know what versions of JAXB the various Sun/Oracle JDKs really use?
Can xjc -version
be trusted?
YES. It will give you the version of the XJC tool.
Can xjc -version
be trusted to give the version of the JAXB (JSR-222) Runtime Implementation?
NO:
JAXB RI and the JAXB Impl Included in the JDK/JRE
Java SE implementations (version 6 and above) are required to include a version of JAXB (JSR-222). What is often (but not required to be) included is a package renamed version of the JAXB RI. So if you run the following:
import javax.xml.bind.JAXBContext;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Demo.class);
System.out.println(jc.getClass());
}
}
You get:
class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
If you download a version of the JAXB-RI and add it to your class path and re-run the same demo code the output will change to the following:
class com.sun.xml.bind.v2.runtime.JAXBContextImpl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With