Java 如何从 ANT 执行 JAXB 编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3630474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute the JAXB compiler from ANT
提问by ams
I am using JAXB on a project. the attraction of JAXB is that it is bundled with the JDK, I have been to use xjc.exe on the command line to generate the .java files from a schema. I can't seem to find the JAXB ant task, sure there is a download at http://jaxb.java.nethowever i want to use the JAXB that is bundled into the JDK is there some way to call JAXB from ant what class does the xjc.exe call on?
我在一个项目上使用 JAXB。JAXB 的吸引力在于它与 JDK 捆绑在一起,我一直在命令行上使用 xjc.exe 从模式生成 .java 文件。我似乎找不到 JAXB ant 任务,确定在http://jaxb.java.net上有下载,但是我想使用捆绑到 JDK 中的 JAXB 是否有某种方法可以从 ant 调用 JAXB 什么xjc.exe 调用的类?
采纳答案by ams
<target name="generate-jaxb-code">
<java classname="com.sun.tools.internal.xjc.XJCFacade">
<arg value="-p" />
<arg value="com.example"/>
<arg value="xsd/sample.xsd" />
</java>
</target>
Just went hunting in the tools.jar and found the XJCFacade.class in com.sun.tools.internal tested the above code it works it produces the output as xjc.exe It seems that XJC.exe calls this code com.sun.tools.internal.xjc.XJCFacade
刚刚在tools.jar中搜索并发现com.sun.tools.internal中的XJCFacade.class测试了上面的代码它工作它产生输出为xjc.exe似乎XJC.exe调用此代码com.sun.tools .internal.xjc.XJCFacade
One of my key requirements was that the ant file had work within eclipse without having to include a path name to the JDK that way the file would be portable across operating systems. I am assuming that tools.jar is included on the classpath via the installed JRE preferences options.
我的一个关键要求是 ant 文件可以在 eclipse 中工作,而不必包含 JDK 的路径名,这样文件就可以跨操作系统移植。我假设 tools.jar 通过已安装的 JRE 首选项选项包含在类路径中。
回答by bdoughan
Here is a helpful link:
这是一个有用的链接:
Java SE 6 does not ship the Ant task (see 7.1.3):
Java SE 6 不提供 Ant 任务(参见 7.1.3):
Essentially they do the following:
本质上,他们执行以下操作:
<target name="xjc" description="....">
<exec executable="${jdk.dir}/bin/xjc.exe">
<arg value="-d"/>
<arg value="${src.dir}"/>
<arg value="-p"/>
<arg value="com.mydomain.jaxb"/>
<arg value="${etc.dir}/myschema.xsd"/>
</exec>
</target>
回答by lexicore
You cant find several sample Ant/JAXB projects in JAXB2 Basics:
您在 JAXB2 Basics 中找不到几个示例 Ant/JAXB 项目: