[英]How to use jaxb2-annotate-plugin with XJC in command line
I'm building java classes based on an xsd using "jaxb-ri" in command line (xjc.bat). 我正在命令行(xjc.bat)中使用“jaxb-ri”基于xsd构建java类。 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. 我想使用jaxb2-annotate_plugin在XmlType注释中设置命名空间,但我不知道如何将此插件添加到xjc类路径并激活它。
here is my external bindings.xjb file : 这是我的外部bindings.xjb文件:
<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. 当我执行此命令时,我收到一条错误消息,指出不支持“ http://annox.dev.java.net ”。
Thanks in advance. 提前致谢。
Disclaimer: I'm the author of jaxb2-annotate-plugin . 免责声明:我是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. Ant和Maven有一些示例 , Ant的一个示例是关闭命令行的用法。
Next, I wonder what is in xjc.bat
. 接下来,我想知道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 the jaxb2-annotate-plugin
. 如果它从Java xjc.exe
调用xjc.exe
,这很可能根本不适用于第三方插件,而不仅仅是jaxb2-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.**
. 原因是随Java一起发布的XJC版本有一个重命名的包: com.sun.tools.**
- > com.sun.tools.internal.**
。 This breaks, naturally compagtibility with plugins. 这打破了,自然与插件的兼容性。 So please make sure xjc.bat
does not call the xjc.exe
contained in the Java distro. 因此,请确保xjc.bat
不会调用Java发行版中包含的xjc.exe
。
I hope xjc.bat
calls com.sun.tools.xjc.XJCFacade
from JAXB RI Jars. 我希望xjc.bat
从JAXB RI Jars调用com.sun.tools.xjc.XJCFacade
。
To execute the plugin you'll need two things: 要执行插件,您需要两件事:
-Xannotate
command line parameter. 使用-Xannotate
命令行参数打开插件。 These dependencies are: 这些依赖关系是:
<!-- JAXB2 Basics library -->
<include name="jaxb2-basics-*.jar"/>
<include name="jaxb2-basics-annotate*.jar"/>
<!-- JAXB2 Basics library dependencies -->
<include name="annox-*.jar"/>
<include name="javaparser-*.jar"/>
<include name="commons-beanutils-*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="commons-lang3-*.jar"/>
Here's the full dependency tree (with versions): 这是完整的依赖树(带有版本):
[INFO] org.jvnet.jaxb2_commons:jaxb2-basics-annotate:jar:1.0.3-SNAPSHOT
[INFO] +- org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.8.1:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.2.7:provided
[INFO] | +- com.sun.xml.bind:jaxb-core:jar:2.2.7:provided
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.2.11:provided
[INFO] | | \- com.sun.istack:istack-commons-runtime:jar:2.16:provided
[INFO] | \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:provided
[INFO] | \- javax.xml.bind:jsr173_api:jar:1.0:provided
[INFO] +- com.sun.xml.bind:jaxb-xjc:jar:2.2.7:provided
[INFO] +- org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-testing:jar:0.9.0:test
[INFO] | \- org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:jar:0.9.0:test
[INFO] | +- org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-core:jar:0.9.0:test
[INFO] | | +- com.sun.org.apache.xml.internal:resolver:jar:20050927:test
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:2.0.9:test
[INFO] | | +- org.sonatype.plexus:plexus-build-api:jar:0.0.7:test
[INFO] | | \- org.apache.maven:maven-project:jar:2.0.9:test
[INFO] | | +- org.apache.maven:maven-settings:jar:2.0.9:test
[INFO] | | +- org.apache.maven:maven-profile:jar:2.0.9:test
[INFO] | | +- org.apache.maven:maven-model:jar:2.0.9:test
[INFO] | | +- org.apache.maven:maven-artifact-manager:jar:2.0.9:test
[INFO] | | | +- org.apache.maven:maven-repository-metadata:jar:2.0.9:test
[INFO] | | | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:test
[INFO] | | +- org.apache.maven:maven-plugin-registry:jar:2.0.9:test
[INFO] | | \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:test
[INFO] | | \- classworlds:classworlds:jar:1.1-alpha-2:test
[INFO] | +- org.codehaus.plexus:plexus-utils:jar:1.5.15:test
[INFO] | +- org.jvnet.jaxb2.maven2:maven-jaxb22-plugin:jar:0.9.0:test
[INFO] | \- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.2:test
[INFO] | \- org.apache.maven:maven-artifact:jar:3.0:test
[INFO] +- org.jvnet.annox:annox:jar:1.0.1:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] | +- commons-io:commons-io:jar:1.2:compile
[INFO] | \- com.google.code.javaparser:javaparser:jar:1.0.11:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO] \- org.hamcrest:hamcrest-core:jar:1.3:test
Maven stuff is unrelated, otherwise you should be able to see the versions. Maven的东西是无关的,否则你应该能够看到版本。
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? 为什么在命令行中实际需要它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.