Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
I've had to confirm which JAXB version I've been using for my runtime. In my search through various forums I've come across some code that more or less worked, but it wasn't very robust and wasn't explained well. I've put this together to answer the question properly.

This code will determine which JAXB-RI runtime version is being used. This will not work for Moxy or any other JAXB implementation other than the V2 RI. I could not find the equivalent code for Moxy, so instead of the code failing with a ClassCastException, I make sure that the V2 RI is being used before trying to get the version number.
 JAXB Version Code
JAXBContext jaxbCtx = JAXBContext.newInstance("net.igorkromin");
if (jaxbCtx instanceof com.sun.xml.bind.v2.runtime.JAXBContextImpl) {
System.out.println("JAXB Version: " +
((com.sun.xml.bind.v2.runtime.JAXBContextImpl) jaxbCtx).getBuildId());
else {
System.out.println("Unknown JAXB implementation: " + jaxbCtx.getClass().getName());

My output is something like this:
JAXB Version: 2.2.11


Skip down to comments...
Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...