users@jaxb.java.net

RE: Get "Provider xx not a subtype" when adding JAXB extension to XJC

From: KARR, DAVID <dk068x_at_att.com>
Date: Thu, 22 Jan 2015 15:31:53 +0000

> -----Original Message-----
> From: KARR, DAVID
> Sent: Tuesday, January 20, 2015 8:35 AM
> To: users_at_jaxb.java.net
> Subject: Get "Provider xx not a subtype" when adding JAXB extension to XJC
>
> This is a variation of a question I asked last week, which I didn't get
> any response to.
>
> I can run XJC on a particular XSD and successfully generate classes. If I
> add to the classpath either of two particular JAXB extensions I'm trying
> to use, it fails with a stacktrace like the following:
> -----------------
> Exception in thread "main" java.util.ServiceConfigurationError:
> com.sun.tools.xjc.Plugin: Provider
> dk.conspicio.jaxb.plugins.XmlElementWrapperPlugin not a subtype
> at java.util.ServiceLoader.fail(ServiceLoader.java:231)
> at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
> at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:369)
> at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
> at com.sun.tools.xjc.Options.findServices(Options.java:924)
> -----------------
>
> I'm currently using a local copy of the "ElementWrapper" plugin and a
> reference to the "fluent API" plugin. If I remove the reference to the
> "ElementWrapper" plugin from the classpath, this error refers to the
> "fluent API" plugin.
>
> I'm adding references to the following jars in the classpath:
> * jaxb-xjc
> * jaxb-impl
> * jaxb-api
> * element wrapper jar
> * fluent api jar
> * activation-1.1.1.jar
> * jsr173 jar
>
> I'm currently using version 2.2.6 of the jaxb jars.
>
> I've tested this sequence in a shell script, just calling XJCFacade
> directly. I've tested this in an Ant build script, using the Ant XJC
> task. I've tested this in Gradle, using the same Ant XJC task. All of
> these fail with the same result.
>
> However, I've also tested this in Maven, using the "cxf-xjc-plugin" Maven
> plugin. This is working, processing the same schema and adding the same
> extensions. This has actually been working like this for quite a while,
> but I'm trying to convert this application build from Maven to Gradle.
> This obstacle is preventing this.

I've determined that my test shell script doesn't even need to process any schemas, as this error happens before it starts processing the xjc command line arguments, so that makes it easier to set up the test.

I've also verified this on both my Windows 7 laptop and a CentOS VM.

This is my current shell script:
---------------------
#! /bin/bash
java -classpath "lib/commons-beanutils-1.7.0.jar;lib/commons-lang-2.2.jar;lib/commons-logging-1.1.1.jar;lib/istack-commons-runtime-2.16.jar;lib/jaxb2-basics-runtime-0.6.5.jar;lib/jaxb2-basics-tools-0.6.5.jar;lib/jaxb-api-2.2.7.jar;lib/jaxb-core-2.2.7.jar;lib/jaxb-fluent-api-2.1.8.jar;lib/jaxb-xew-plugin-1.4.jar;lib/jaxb-xjc-2.2.7.jar" com.sun.tools.xjc.XJCFacade -extension
--------------------

To set this up, you just have to download these artifacts (search for the base name on maven central) into a "lib" directory and put this script in the parent of that "lib" directory and run it. When you run it, it should complain at the top about command-line arguments, but at the end of the output you should see something like this:

Exception in thread "main" java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider org.jvnet.jaxb2_commons.tools.xjc.plugin.fluent_api.XjcFluentApiPlugin not a subtype
        at java.util.ServiceLoader.fail(ServiceLoader.java:231)
        at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:369)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
        at com.sun.tools.xjc.Options.findServices(Options.java:957)
        at com.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
        at com.sun.tools.xjc.Driver.usage(Driver.java:534)
        at com.sun.tools.xjc.Driver._main(Driver.java:132)
        at com.sun.tools.xjc.Driver.access$000(Driver.java:80)
        at com.sun.tools.xjc.Driver$1.run(Driver.java:103)