Future strategy for the JAXB2-Maven-Plugin

91 views
Skip to first unread message

Lennart Jörelid

unread,
Oct 8, 2018, 12:13:52 PM10/8/18
to mojohaus-dev
Hello all,

I am pondering the future of the JAXB2 Maven plugin, following three rather problematic properties:

  • The JAXB2-Maven-Plugin was implemented to delegate Java compilation and XML or Schema compilation to the tools within the JDK.
  • The JAXB support including tooling is removed from JDK 11 and onwards.
  • The tooling contains subtle but rather serious bugs which has created a decently complex mess of workarounds within the plugin. For example - the XML schema created from one of the integration tests within the plugin generates incorrect results in JDK9+, as shown in the snippet below. The JDK8 schemagen tool generates a schema element [including child elements] with correct namespace prefix, implying that the schema element correctly resides within the XMLSchema namespace. The JDK9 and JDK10 schemagen tools incorrectly generates a schema element without a namespace prefix, implying that the schema element is placed within the targetNamespace, which is normally the target of each schemagen compilation for each unique XML namespace within the compilation unit.
Snippets:

JDK 1.8 execution:
==================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://acme.com/customer-api" xmlns:tns="http://acme.com/customer-api" xmlns:xs="http://www.w3.org/2001/XMLSchema">

JDK 9,10 execution:
================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema version="1.0" targetNamespace="http://acme.com/customer-api" xmlns:tns="http://acme.com/customer-api" xmlns:xs="http://www.w3.org/2001/XMLSchema">

So ... We have at least 3 options here:

  1. File a bug report against the development of JDK 9 and 10 (but if I understand correctly, there is no development going on within these JDK releases), and hope that this bug gets fixed.
  2. Find another tool to generate XML Schema from JAXB annotations. This seems like a better way than the JDK tooling bug approach above, although it requires a more-or-less complete rewrite of the plugin's internals. Question: What polyglot Annotation processors or DSL generators do you recommend?
  3. Just freeze development of JMP at JDK 8; simply put the codebase into sunset. This is doable, but not really desirable.
What do you think? Which way should we take?

Anders Hammar

unread,
Oct 16, 2018, 2:21:20 AM10/16/18
to mojoha...@googlegroups.com
Hi Lennart,

I think that we should go with the jaxb (and jaxws as well) libraries and tools that were broken out ot JDK.[1] and is now developed at Eclipse. I started to look at this last week and was suprised about the current state of them though. Not much developed it seems even though there are  lots of filed issues. But I just loked briefly.
I did see that you already filed a ticket there for the schemagen issue you talked about - good!

Wrt the mojo plugin I'd say that we foxuc on jdk 11 from now on. Bump minor for this and leave the current minor release for JDK 8. JDK 9 and 10 is no point in supporting as the yare EOL already. In theory we could backport fixed for the JDK 8 version trail, but that won't happen I think. But if someone really wants it and steps up it could happen.

So, basically your option 1 but focus on JDK 11 support but use the jaxb-ri library that is now with Eclipse. So any bugs shouldn't be filed againt any JDK but that library.


/Anders

--
You received this message because you are subscribed to the Google Groups "mojohaus-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojohaus-dev...@googlegroups.com.
To post to this group, send email to mojoha...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mojohaus-dev/3bd959d7-c9d7-4d9d-ae8a-5034e07c25a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Veithen

unread,
Mar 24, 2019, 6:15:42 PM3/24/19
to mojoha...@googlegroups.com
On Mon, Oct 8, 2018 at 5:13 PM Lennart Jörelid
<lennart...@gmail.com> wrote:
>
> Hello all,
>
> I am pondering the future of the JAXB2 Maven plugin, following three rather problematic properties:
>
> The JAXB2-Maven-Plugin was implemented to delegate Java compilation and XML or Schema compilation to the tools within the JDK.
> The JAXB support including tooling is removed from JDK 11 and onwards.
> The tooling contains subtle but rather serious bugs which has created a decently complex mess of workarounds within the plugin. For example - the XML schema created from one of the integration tests within the plugin generates incorrect results in JDK9+, as shown in the snippet below. The JDK8 schemagen tool generates a schema element [including child elements] with correct namespace prefix, implying that the schema element correctly resides within the XMLSchema namespace. The JDK9 and JDK10 schemagen tools incorrectly generates a schema element without a namespace prefix, implying that the schema element is placed within the targetNamespace, which is normally the target of each schemagen compilation for each unique XML namespace within the compilation unit.

That issue is in fact caused by MNG-6506 and there is a workaround:
https://github.com/mojohaus/jaxb2-maven-plugin/pull/124.

>
> Snippets:
>
> JDK 1.8 execution:
> ==================
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <xs:schema version="1.0" targetNamespace="http://acme.com/customer-api" xmlns:tns="http://acme.com/customer-api" xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> JDK 9,10 execution:
> ================
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <schema version="1.0" targetNamespace="http://acme.com/customer-api" xmlns:tns="http://acme.com/customer-api" xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> So ... We have at least 3 options here:
>
> File a bug report against the development of JDK 9 and 10 (but if I understand correctly, there is no development going on within these JDK releases), and hope that this bug gets fixed.
> Find another tool to generate XML Schema from JAXB annotations. This seems like a better way than the JDK tooling bug approach above, although it requires a more-or-less complete rewrite of the plugin's internals. Question: What polyglot Annotation processors or DSL generators do you recommend?
> Just freeze development of JMP at JDK 8; simply put the codebase into sunset. This is doable, but not really desirable.
>
> What do you think? Which way should we take?
>

Lennart Jörelid

unread,
Mar 25, 2019, 3:01:40 AM3/25/19
to mojoha...@googlegroups.com
I merged this change to just not keep this stalled anymore. 

It seems that XML namespaces are somewhat under-explained in the development community overall - implying that the support for them in may places is lackluster.
However, I basically think it is the wrong approach - 
  • XML is a standard, and it is important that all JDK versions produce the same (and usable) XML from the same sources. Without tweaking the project itself.

You received this message because you are subscribed to a topic in the Google Groups "mojohaus-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojohaus-dev/4AQa45VHo3c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojohaus-dev...@googlegroups.com.

To post to this group, send email to mojoha...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: l...@jguru.se
| URL:   www.jguru.se
| Phone
| (skype):    jgurueurope
| (intl):     +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+

Andreas Veithen

unread,
Mar 25, 2019, 4:36:07 AM3/25/19
to mojoha...@googlegroups.com
The issue actually has nothing to do with support for namespaces, and
neither JAXB nor the JDK are at fault here. The problem is caused by a
latent bug in Plexus Classworlds that is triggered by a change in the
ClassLoader class in Java 9. It causes package annotations not to be
loaded. This ultimately manifests itself as problems with XML
namespaces because the package annotations that get missed in this
case define mappings between Java packages/classes and XML namespaces.

The net effect is the same as if you removed those annotations from
the JAXB code. Obviously neither JAXB nor the JDK can be blamed for
this.

Because of the specifics of the bug in Classworlds, it turns out that
it's possible to work around it by preloading the package-info classes
(which contain those package annotations), which is what the PR does.

Andreas
> To view this discussion on the web visit https://groups.google.com/d/msgid/mojohaus-dev/CAJ1fz80Rpe6_QXuQzZb59r1__rB%2B0OXVrPb4SLZhrR4yDK12qQ%40mail.gmail.com.

Jochen Wiedmann

unread,
Mar 25, 2019, 5:11:24 AM3/25/19
to mojoha...@googlegroups.com
On Mon, Mar 25, 2019 at 9:36 AM Andreas Veithen
<andreas...@gmail.com> wrote:
>
> The issue actually has nothing to do with support for namespaces, and
> neither JAXB nor the JDK are at fault here. The problem is caused by a
> latent bug in Plexus Classworlds that is triggered by a change in the
> ClassLoader class in Java 9.

Be that as it may. Lennarts question needs an answer, due to the
simple fact, that we can no longer depend on JAXB being available with
the JDK.

I have to admit, that I didn't follow the JAXB 2 development over the
past years, so I am not really uptodate. Please correct me, if I am
wrong with the following:

- The JAXB RI (which has been part of the JDK) is nowadays maintained on [1].
- I doubt, that there is real development. However, there are forks.
which do seem to be somewhat active, for example or [3]. (Just notice,
that this is, indeed, Lennarts.)
I see nothing, which is pushing out releases?


My personal recommendation would be to introduce adapters for
launching the binding generator. The respective adapters (and adapter
versions) could be locked to a particular version of JAXB-RI,
EclipseLink, or whatever else is out in the wild. Users should be able
to select a suitable adapter / adapter version, and keep that stable
over different versions of the Mojo, thus ensuring stable builds.

Questions: Do we still depend on the presence of an external xjc, or
can we have the RI embedded? Same question for EclipseLink?

Jochen


1: https://github.com/eclipse-ee4j/jaxb-ri
2: https://github.com/highsource/maven-jaxb2-plugin
3: https://github.com/lennartj/jaxb-ri

Andreas Veithen

unread,
Mar 25, 2019, 5:21:31 PM3/25/19
to mojoha...@googlegroups.com
The plugin uses the com.sun.tools.xjc.Driver API and according to Git
history this has been the case for at least 4 years. Note that this
class is provided by the standalone JAXB RI, not the JRE/JDK (which
provides com.sun.tools.internal.xjc.Driver). Currently the plugin uses
the JAXB artifacts with group ID org.glassfish.jaxb. I think that is
the right choice. They appear to be actively maintained: the most
recent jaxb-xjc is 2.3.2 from beginning of 2019. What's missing right
now is to make the plugin work on recent Java versions. I think that
with my workaround for the Classworlds bug, it should be enough to
upgrade jaxb-xjc to the most recent version and get rid of the build
profiles that attempt to work around Java compatibility issues in
previous versions of jaxb-xjc.

Andreas
> --
> You received this message because you are subscribed to the Google Groups "mojohaus-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mojohaus-dev...@googlegroups.com.
> To post to this group, send email to mojoha...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mojohaus-dev/CAF8HOZKmwogZKXbGuF-%3Dy9M1e0y0P26Dm9jeBq0KeabCQuKqQA%40mail.gmail.com.

Andreas Veithen

unread,
Mar 25, 2019, 6:08:14 PM3/25/19
to mojoha...@googlegroups.com
Ah, the other thing we need to do to get the build working on Java 11
is to update the relevant integration tests to include a dependency on
jaxb-api because that's no longer part of the JRE.

Andreas

On Mon, Mar 25, 2019 at 9:21 PM Andreas Veithen

Andreas Veithen

unread,
Mar 25, 2019, 6:59:51 PM3/25/19
to mojoha...@googlegroups.com
Done: https://github.com/mojohaus/jaxb2-maven-plugin/pull/126.

Andreas

On Mon, Mar 25, 2019 at 10:08 PM Andreas Veithen
Reply all
Reply to author
Forward
0 new messages