I'm building java classes based on an xsd using "jaxb-ri" in command line (xjc.bat). I want to set a namespace in an XmlType annotation using jaxb2-annotate_plugin but I don't know how to add this plugin to xjc classpath and acitvate it.
here is my external bindings.xjb file :
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net"
jxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jxb:bindings schemaLocation="myschema.xsd" node="/xs:schema">
<jxb:bindings node="xs:complexType[@name='MyType]">
<annox:annotateClass>@javax.xml.bind.annotation.XmlType(namespace="urn:myschematwo")</annox:annotateClass>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
My command line is :
D:/jaxb-ri/bin/xjc.bat -p "com.jaxb.mypackage" -d
"D:/myproject/src/main/java" D:/myschema.xsd -b "D:/bindings.xjb"
-extension
When I execute this command, I have an error message saying that "http://annox.dev.java.net" is not supported.
Thanks in advance.
Disclaimer: I'm the author of jaxb2-annotate-plugin.
First, I don't provide sample for command line as (as far as I know) nobody uses command line or batch scripts for schema compilation. At least up to date there were no requests for that. There are samples for Ant and Maven, the one for Ant is the closes to the command line usage.
Next, I wonder what is in
xjc.bat
.If it calls
xjc.exe
from Java distibution, this most probably won't work with third-party plugins at all, not just with thejaxb2-annotate-plugin
. The reason is that the XJC version which is distributed with Java has a renamed package:com.sun.tools.**
->com.sun.tools.internal.**
. This breaks, naturally compagtibility with plugins. So please make surexjc.bat
does not call thexjc.exe
contained in the Java distro.I hope
xjc.bat
callscom.sun.tools.xjc.XJCFacade
from JAXB RI Jars.To execute the plugin you'll need two things:
-Xannotate
command line parameter.These dependencies are:
Here's the full dependency tree (with versions):
Maven stuff is unrelated, otherwise you should be able to see the versions.
Hope this helps.
To be honest, I am a bit reluctant to invest time in batch/command-line sample. But if you'll get one working, I'd add it to samples.
Why do you actually need it in the command line?