如何从在JDK类链接JAR使蚂蚁preFER类? [英] How to make Ant prefer classes from a linked JAR over JDK classes?

查看:159
本文介绍了如何从在JDK类链接JAR使蚂蚁preFER类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立dom4j的JAR,其中包括一个XML的API JAR其中包含一个DOM API是比附带最近的JDK以上。

I am trying to build the dom4j JAR, which includes an xml-apis JAR which contains a DOM API that is older than that shipped with more recent JDKs.

不过,即使在源和目标的编译器属性设置为1.3的编译文件,即使XML的API JAR包含在构建路径,蚂蚁仍然试图编译对另一dom4j的,新的,W3C API (我猜一个来自JDK安装)。

However, even though in the build file the source and target compiler attributes are set to 1.3, and even though the xml-apis JAR is included in the build path, Ant still tries to compile dom4j against another, newer, w3c API (I guess one from a JDK installation).

下面是有关的蚂蚁code:

Here's the relevant Ant code:

<path id="compile.classpath">
    <fileset dir="./lib/endorsed">
        <include name="*.jar" />
    </fileset>
    <fileset dir="./lib">
        <include name="*.jar" />
    </fileset>
</path>

  <target name="compile" depends="prepare-src">
    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${debug}"
           optimize="${optimize}"
           target="1.3"
           source="1.3"
           deprecation="${deprecation}"
           classpathref="compile.classpath">
    </javac>
  </target>

这应该使用的JAR是在LIB /认可,但它在编译期间不是使用。

the JAR that should be used is in lib/endorsed, but it's not used during compilation.

为什么?

推荐答案

您可以修改启动classpath中并没有这种支持与ANT特定属性,但我认为它应该是的java .endorsed.dirs 属性(在原始的javac):

You could modify the boot classpath and there is support for that with a specific attribute in ANT, but I think it should be the java.endorsed.dirs property (in raw javac):

javac -Djava.endorsed.dirs=/some/path/lib/endorsed ...

或者以 compilerarg ANT子元素:

Or with a compilerarg ANT sub-element:

<target name="compile" depends="prepare-src">
    <javac srcdir="${build.src}"
       destdir="${build.dest}"
       debug="${debug}"
       optimize="${optimize}"
       target="1.3"
       source="1.3"
       deprecation="${deprecation}"
       classpathref="compile.classpath">
    <compilerarg value="-Djava.endorsed.dirs=/some/path/lib/endorsed"/>
</javac>

您应该在批准目录未添加到类路径的引导类路径和类路径来解决所需类型之前的任何认可的目录进行检查。这意味着JDK的新的DOM实现将首先找到。

You shouldn't add the endorsed directory to the classpath as the boot classpath and any endorsed directories are checked before the classpath to resolve required types. This would mean the JDK's newer DOM implementation would be found first.

这篇关于如何从在JDK类链接JAR使蚂蚁preFER类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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