Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JAXB extensions on xjc command line

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?

like image 720
David M. Karr Avatar asked Jan 26 '15 05:01

David M. Karr


People also ask

How do I use JAXB XJC?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.

Is XJC a JAXB?

7.1. The JAXB-2 Maven plugin uses the JDK-supplied tool XJC, a JAXB Binding compiler tool that generates Java classes from XSD (XML Schema Definition). By default, this plugin locates XSD files in src/main/xsd.

What is JAXB XJC jar?

Old JAXB XJCContains source code needed for binding customization files into java sources. In other words: the *tool* to generate java classes for the given xml representation.

What is XJC command?

Use the Java™ Architecture for XML Binding (JAXB) tools to generate Java classes from an XML schema with the xjc schema compiler tool.


1 Answers

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.

like image 141
lexicore Avatar answered Oct 20 '22 09:10

lexicore