如何在命令行中使用带有XJC的jaxb2-annotate-plugin [英] How to use jaxb2-annotate-plugin with XJC in command line
问题描述
我正在命令行(xjc.bat)中使用jaxb-ri基于xsd构建java类。
我想使用jaxb2-annotate_plugin在XmlType注释中设置命名空间,但我不知道如何将此插件添加到xjc classpath并激活它。
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.
这是我的外部bindings.xjb文件:
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>
我的命令行是:
D:/jaxb-ri/bin/xjc.bat -p "com.jaxb.mypackage" -d
"D:/myproject/src/main/java" D:/myschema.xsd -b "D:/bindings.xjb"
-extension
当我执行此命令,我收到一条错误消息 http://annox.dev.java.net 不受支持。
When I execute this command, I have an error message saying that "http://annox.dev.java.net" is not supported.
提前致谢。
推荐答案
免责声明:我是 jaxb2-annotate-plugin 的作者。
首先,我不提供命令行示例(据我所知)没有人使用命令行或批处理脚本进行模式编译。至少最新没有要求。 样本: //github.com/highsource/jaxb2-annotate-plugin/blob/master/samples/annotate/project-build.xml\"rel =nofollow> Ant 和 Maven ,Ant的一个是关闭命令行用法。
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.
接下来,我想知道 xjc.bat
中的内容。
Next, I wonder what is in xjc.bat
.
如果它从Java distibution调用 xjc.exe
,这很可能根本不适用于第三方插件,而不仅仅是 JAXB2-注释-插件
。原因是随Java一起发布的XJC版本有一个重命名的包: com.sun.tools。**
- > com.sun。 tools.internal。**
。这打破了,自然与插件的兼容性。因此,请确保 xjc.bat
不会调用Java发行版中包含的 xjc.exe
。
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
. 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 sure xjc.bat
does not call the xjc.exe
contained in the Java distro.
我希望 xjc.bat
来电 com.sun.tools.xjc.XJCFacade
来自JAXB RI Jars。
I hope xjc.bat
calls com.sun.tools.xjc.XJCFacade
from JAXB RI Jars.
要执行该插件,您需要两件事:
To execute the plugin you'll need two things:
- 在类路径中包含所有必需的依赖项。
- 使用
-Xannotate
命令行参数打开插件。
- Include all the required dependencies to the classpath.
- Turn the plugin on using
-Xannotate
command line parameter.
这些依赖关系是:
<!-- 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的东西是无关的,否则你应该是能够看到版本。
Maven stuff is unrelated, otherwise you should be able to see the versions.
希望这会有所帮助。
说实话,我有点不愿意在批处理/命令行示例中投入时间。但是,如果你有一个工作,我会把它添加到样本。
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?
这篇关于如何在命令行中使用带有XJC的jaxb2-annotate-plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!