JAXB Libraries (RI) vs. JDK

Using maven there are several plugins to support, eg. generating JAXB classes from XSD for example. org.codehaus.mojo: jaxb2-maven-plugin and org.jvnet.jaxb2.maven2: maven-jaxb2-plugin. The newest version has dependencies on, for example, org.glassfish.jaxb: jaxb-xjc and org.glassfish.jaxb: jaxb-runtime (in version 2.2.11).

But I'm wondering what happens if I use the ones that generate my classes from XSD, but only use JDK 8 (which contains version 2.2.8): would there be a risk that I get runtime errors?
Is it necessary or recommended to always use the jaxb-runtime that matches the version of jaxb-xjc I used to generate my classes from XSD?

Of course, I could just override the jaxb-xjc dependencies, etc. and explicitly use version 2.2.8. But even then, I'm wondering if I end up doing the same as if I used the JDK 8 xjc tool directly?


source to share

1 answer

You have three stages:

  • (1) generating schema generated code
  • (2) compiling schema-derived code
  • (3) lead time

Most importantly, the JAXB API you are using to compile (2) is compatible with the JAXB API you are using at runtime (3). If this is not the case, you can compile code that uses some annotation that is later not available at runtime. And you will see the error first at runtime.

As for (1) vs. (2) this is also necessary. If you are building JAXB 2.2.x and using JAXB 2.1.x to compile, this does not necessarily work. But this is less critical, as it will be a compilation error that you will have to fix.

So if the problem is just the JAXB version used versus the JAXB version built into the JDK, I wouldn't bother with that. As long as it compiles, you are as safe as ever.



All Articles