如何让 Ant 在 javac 中使用 JAXB 2.2.x 而不是 Java 6 SE JAXB 类? [英] How can I make Ant use JAXB 2.2.x instead of Java 6 SE JAXB classes in javac?

查看:23
本文介绍了如何让 Ant 在 javac 中使用 JAXB 2.2.x 而不是 Java 6 SE JAXB 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新旧应用程序以使用 Java 6 SE 而不是 Java 5 SE.该应用程序使用 JAXB,在 Java 5 SE 下,它在类路径上有 JAXB 参考实现 jars.当我转向 Java 6 SE(更新 38)时,我遇到了一些障碍(参见 链接的 Stackoverflow 问题),我在一些帮助下解决了这个问题.

I'm in the process of updating a legacy application to use Java 6 SE instead of Java 5 SE. The app uses JAXB, and under Java 5 SE it have the JAXB reference implementation jars on the classpath. When I moved to Java 6 SE (update 38), I hit a few bumps (see linked Stackoverflow question) that I resolved with some help.

所以接下来引起麻烦的是项目 Ant 构建脚本.当 Ant 编译任务执行时,它会选择 Java 6 SE 附带的 JAXB 嵌入式版本,而不是我在类路径(JAXB 2.2.6 版本)中包含的 jar 版本.我相信 Java 6 SE 包括 JAXB 2.1.x.这导致编译时错误如下:

So the next thing that is causing trouble is the project Ant build script. When the Ant compile task executes, it picks up the embedded version of JAXB that comes with Java 6 SE rather than the version from the jars that I have included on the classpath (the JAXB 2.2.6 release). I believe Java 6 SE includes JAXB 2.1.x. This is causing compile time error like this:

[javac] location: @interface javax.xml.bind.annotation.XmlElementRef
[javac]     @XmlElementRef(name = "abbrev", type = JAXBElement.class, required = false)

在这种情况下,JAXB 2.1.x 中的 @XmlElementRef 不存在required"属性,但在 2.2.x 中存在.

In this case, the 'required' attribute did not exist in for the @XmlElementRef in JAXB 2.1.x, but it does in 2.2.x.

如何更改我的 Ant 构建脚本,使其从构建类路径中获取 JAXB 2.2.6 jar,而不是打包在 Java 6 SE JDK 中的类?

更新:基于彼得回答的解决方案

UPDATE: Solution based on Peter's answer

<target name="compile" depends="clean">
    <javac deprecation="on" 
            classpathref="prj.classpath" 
            srcdir="${src}" 
            destdir="${build.dir}" 
            debug="on" 
            debuglevel="lines,vars,source" 
            source="1.6">
        <compilerarg value="-Djava.endorsed.dirs=${lib.ext.dir}/jaxb"/>
    </javac>
</target>

推荐答案

我相信认可库文件夹的概念是您的朋友.

I believe concept of endorsed library folder is your friend.

即切换:

<compilerarg value="-Djava.endorsed.dirs=/some/path/lib/endorsed"/>

背书中存在的那些 jar 将被视为优先于加载的任何其他类(我相信).

Those jars present in the endorsed are to be considered prio to any other classes loaded (I believe).

有关更完整的示例,请参阅以下正确答案:如何让 Ant 更喜欢来自链接 JAR 的类而不是 JDK 类?

For more complete sample see the correct answer on: How to make Ant prefer classes from a linked JAR over JDK classes?

这篇关于如何让 Ant 在 javac 中使用 JAXB 2.2.x 而不是 Java 6 SE JAXB 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆