如何使用 jaxb 和 Ant xjc 任务处理多个 xsd 模式?
我使用 jaxb 在 Ant 脚本中从 xml 模式生成 java 对象类,如下所示:
<!-- JAXB compiler task definition -->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"
classpathref="master-classpath"/>
<!-- Generates the source code from the ff.xsd schema using jaxb -->
<target name="option-generate" description="Generates the source code">
<mkdir dir="${generated-src.dir}/${option.dir}"/>
<xjc schema="${config.dir}/ff.xsd" destdir="${generated-src.dir}"
package="${option.package.name}">
<arg value="-Xcommons-lang" />
<arg value="-Xcommons-lang:ToStringStyle=SHORT_PREFIX_STYLE" />
<produces dir="${generated-src.dir}" includes="**/*.java" />
</xjc>
</target>
现在,这对于一种模式(本例中为 ff.xsd)非常有效。如何处理多个模式(即多个 xsd 文件)?
我尝试为每个模式设置一个单独的 ant 任务,但不知何故,这不起作用,因为 Ant 处理第一个任务,然后说以下模式的“文件是最新的”!
I'm using jaxb to generate java object class from xml schemas within an Ant script like so:
<!-- JAXB compiler task definition -->
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask"
classpathref="master-classpath"/>
<!-- Generates the source code from the ff.xsd schema using jaxb -->
<target name="option-generate" description="Generates the source code">
<mkdir dir="${generated-src.dir}/${option.dir}"/>
<xjc schema="${config.dir}/ff.xsd" destdir="${generated-src.dir}"
package="${option.package.name}">
<arg value="-Xcommons-lang" />
<arg value="-Xcommons-lang:ToStringStyle=SHORT_PREFIX_STYLE" />
<produces dir="${generated-src.dir}" includes="**/*.java" />
</xjc>
</target>
Now, this works brilliantly for one schema (ff.xsd in this example). How can I process several schemas (i.e. several xsd files)?
I tried having a separate ant task per schema, but somehow, this doesn't work as Ant process the first task and then says that the "files are up to date" for the following schemas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与 JDK 6 一部分的 JAXB 一起工作似乎 ANT 任务只附带可下载的 JAXB,但由于 JAXB 是 JDK 的一部分,因此采用最新版本的 JAXB 并将其添加到类路径中可能不是一个好主意JDK,因为这意味着您可能需要搞乱类加载器设置,以获取下载的版本而不是 JDK 中的版本。
works with the JAXB that is part of JDK 6 seems that the ANT task only ships with the downloadable JAXB but since JAXB is part of the JDK its probably not a good idea to take the latest release of the JAXB and add to the classpath of the JDK since that means you probably need to mess around with classloader settings, to pickup the downloaded version rather than the version within the JDK.
您还可以使用如下命令将其他 xsd 文件包含在主 xsd 文件中:
You can also just include the other xsd files in your main xsd file, using a command like the following: