我怎样才能让蚂蚁利用JAXB 2.2.x的,而不是Java 6的SE JAXB类的javac? [英] How can I make Ant use JAXB 2.2.x instead of Java 6 SE JAXB classes in javac?

查看:151
本文介绍了我怎样才能让蚂蚁利用JAXB 2.2.x的,而不是Java 6的SE JAXB类的javac?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新遗留应用程序使用Java SE 6,而不是Java 5的SE的过程。该应用程序使用JAXB,并在Java SE 5它具有类路径的JAXB参考实现罐子。当我移动到Java SE 6(更新38),我打了一些颠簸(见<一href=\"http://stackoverflow.com/questions/14223852/jaxb-date-conversions-fail-after-moving-from-java-5-se-to-java-6-se\">linked计算器问题),我有一些帮助解决。

所以这是造成麻烦,接下来的事情就是项目的Ant构建脚本。当蚂蚁编译任务执行时,它拿起JAXB的嵌入式版本附带的Java SE 6,而不是从我已经包含在类路径中(JAXB的2.2.6版本)的罐子的版本。我相信的Java SE 6 JAXB包括2.1.x.这导致编译时错误是这样的:

  [javac的]位置:@interface javax.xml.bind.annotation.XmlElementRef
[javac的] @XmlElementRef(NAME =缩写,键入= JAXBElement.class,所需= FALSE)

在这种情况下,必要的属性没有在JAXB 2.1.x的所述@XmlElementRef存在,但它在2.2.x的确实

我怎样才能改变我的Ant构建脚本,它从构建类路径,而不是被包装在Java SE 6 JDK中的类拿起JAXB 2.2.6罐子吗


更新:根据彼得的答案的解决方案

 &lt;目标名称=编译取决于=干净&GT;
    &所述; javac的德precation =上
            classpathref =prj.classpath
            SRCDIR =$ {src}字符串
            DESTDIR =$ {} build.dir
            调试=上
            DEBUGLEVEL =行,增值分销商,源
            来源=1.6&GT;
        &LT; compilerarg值= - Djava.endorsed.dirs = $ {} lib.ext.dir / JAXB/&GT;
    &LT; / javac的&GT;
&LT; /目标与GT;


解决方案

我相信赞同库文件夹的概念是你的朋友。

即切换:

 &LT; compilerarg值= -  Djava.endorsed.dirs = /一些/路径/ lib中/批准/&GT;

在那些罐子present的认可是要考虑到PRIO加载的任何其他类(我相信)。

有关更完整的示例看到正确答案:<一href=\"http://stackoverflow.com/questions/1388441/how-to-make-ant-$p$pfer-classes-from-a-linked-jar-over-jdk-classes\">How从在JDK类链接JAR使蚂蚁preFER类?

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.

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)

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.

How can I change my Ant build script so that it picks up the JAXB 2.2.6 jars from the build classpath instead of the classes that are packed inside the 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.

Namely switch:

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

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

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

这篇关于我怎样才能让蚂蚁利用JAXB 2.2.x的,而不是Java 6的SE JAXB类的javac?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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