如何让 Ant 更喜欢来自链接 JAR 的类而不是 JDK 类? [英] How to make Ant prefer classes from a linked JAR over JDK classes?

查看:17
本文介绍了如何让 Ant 更喜欢来自链接 JAR 的类而不是 JDK 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建 dom4j JAR,其中包含一个 xml-apis JAR,其中包含一个比最新 JDK 附带的 DOM API 更旧的 DOM API.

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-apis JAR 包含在构建路径中,Ant 仍然尝试针对另一个更新的 w3c API 编译 dom4j(我猜是 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).

这是相关的 Ant 代码:

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/endorsed 中,但在编译期间未使用.

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

怎么会?

推荐答案

您可以修改引导类路径,并且在 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>

您不应将 endorsed 目录添加到类路径中,因为在类路径之前检查引导类路径和任何认可的目录以解析所需的类型.这意味着将首先找到 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.

这篇关于如何让 Ant 更喜欢来自链接 JAR 的类而不是 JDK 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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