How to use JAXB extensions on xjc command line
Asked Answered
H

1

11

I'm working on a related issue here, but I have a separate question. Perhaps it's all part of the same problem, but it seems different.

Because of the problems I'm having running XJC through the Ant task and through the facade, I'm now trying to run it with the command-line "xjc" tool from the JDK.

As in the original problem, I'm trying to use the "Element Wrapper" and "Fluent API" extensions, so my command line is the following:

xjc -extension  -classpath "lib/jaxb-fluent-api-2.1.8.jar;lib/jaxb-xew-plugin-1.4.jar" -Xxew -summary target/xew-summary.txt -instantiate lazy -Xfluent-api schema/serviceCallResults.xsd

These are basically the same parameters I've been sending to the "cxf-jaxb-plugin" Maven plugin, which has been working for a long time. Unfortunately, this "xjc" command line fails with:

unrecognized parameter -Xxew

What might be wrong here?

Halibut answered 26/1, 2015 at 5:50 Comment(0)
E
8

This just does not work, sorry.

XJC plugins must extend the com.sun.tools.xjc.Plugin class. But the XJC which is included into JDK and available as xjc binary (ex. xjc.exe under Windows) is repackaged: com.sun.tools.xjc -> com.sun.tools.internal.xjc.

So in vanilla command line xjc you don't have the com.sun.tools.xjc.Plugin class (which XJC plugins extend) but com.sun.tools.internal.xjc.Plugin.

So CLI xjc just does not work with XJC plugins. The only plugins which still work are those which are repackaged as well. (Ex. com.sun.tools.internal.xjc.addon.code_injector.PluginImpl.)

If do you want command line then try to figure out java -cp ... parameters, this is the only way to make it work with third-party XJC plugins like XEW or JAXB2-Basics.

Elimination answered 26/1, 2015 at 7:40 Comment(2)
As one cannot combine -jar and -cp options, the command line will be something like that java -cp jaxb-api-2.2.7.jar;jaxb-core-2.2.7.jar;jaxb-xjc-2.2.7.jar com.sun.tools.xjc.XJCFacade -d src xsdBuhrstone
@Buhrstone You're right. I've mistaken it for a "shaded" jar in another project.Elimination

© 2022 - 2024 — McMap. All rights reserved.