java 设置蚂蚁引导类路径:JDK 1.7 有一个新的 javac 警告,用于设置没有引导类路径的旧源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7260697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:19:34  来源:igfitidea点击:

Set ant bootclasspath: JDK 1.7 has a new javac warning for setting an older source without bootclasspath

javaantjavacjava-7

提问by initialZero

How do I set the ant bootclasspath in conjunction with -source 1.5 -target 1.5?

如何结合 -source 1.5 -target 1.5 设置 ant 引导类路径?

How can this not be a hardcoded path to the 1.5 JDK? Can I set an environment variable to bootclasspath similar to how JAVA_HOME can be used from ant?

这怎么可能不是 1.5 JDK 的硬编码路径?我可以将环境变量设置为 bootclasspath 类似于如何从 ant 中使用 JAVA_HOME 吗?

Ideally I would like to do something like set an environment variable or pass an argument to ant.

理想情况下,我想做一些类似设置环境变量或将参数传递给 ant 的操作。

回答by martin clayton

Here's an illustration of how you might fetch the Java 5 boot classes location from an environment variable, then use it.

下面是如何从环境变量中获取 Java 5 引导类位置,然后使用它的说明。

First, set the environment variable - say JAVA5_BOOTCLASSES. The propertytaskgives you access to the environment, then the bootclasspathargument of the javactaskpasses the setting to the compiler.

首先,设置环境变量 - say JAVA5_BOOTCLASSES。该property任务使您可以访问环境,然后任务bootclasspath参数将设置传递给编译器。javac

<property environment="env" />
<property name="java5.boot.classpath" value="${env.JAVA5_BOOTCLASSES}" />

<javac source="1.5" target="1.5"
       bootclasspath="${java5.boot.classpath}"
       ...
/>

Note that if the environment variable is not set, Ant will ignore it and proceed without - so the compiler will fall back to the default boot classpath.

请注意,如果未设置环境变量,Ant 将忽略它并继续执行 - 因此编译器将回退到默认引导类路径。

Another option, if appropriate, is to switch off the warnings, and not bother with the bootclasspath. Something like

如果合适,另一种选择是关闭警告,而不用打扰引导类路径。就像是

<javac srcdir= ... >
    <compilerarg arg="-Xlint:-options" />
</javac>

But that's likely to expose you to some subtle bugs.

但这可能会使您暴露在一些微妙的错误中。

回答by soltysh

It's worth noticing that variable JAVA5_BOOTCLASSESshould contain all needed libraries not just rt.jar. In my case it was also jce.jar So it's good to set this variable using this simple snippet when in *nix environment:

值得注意的是,变量JAVA5_BOOTCLASSES应该包含所有需要的库,而不仅仅是 rt.jar。在我的情况下,它也是 jce.jar 所以在 *nix 环境中使用这个简单的代码片段设置这个变量是很好的:

export JAVA5_BOOTCLASSES=""
for i in /usr/lib/jvm/java/jre/lib/*.jar; do 
    export JAVA5_BOOTCLASSES=$JAVA5_BOOTCLASSES:$i
done