简体   繁体   English

设置ant bootclasspath:JDK 1.7有一个新的javac警告,用于设置没有bootclasspath的旧源

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

How do I set the ant bootclasspath in conjunction with -source 1.5 -target 1.5? 如何将ant bootclasspath与-source 1.5 -target 1.5一起设置?

How can this not be a hardcoded path to the 1.5 JDK? 这怎么可能不是1.5 JDK的硬编码路径? Can I set an environment variable to bootclasspath similar to how JAVA_HOME can be used from ant? 我可以将环境变量设置为bootclasspath,类似于如何从ant使用JAVA_HOME吗?

Ideally I would like to do something like set an environment variable or pass an argument to ant. 理想情况下,我想做一些事情,例如设置环境变量或将参数传递给ant。

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 . 首先,设置环境变量 - 比如说JAVA5_BOOTCLASSES The property task gives you access to the environment, then the bootclasspath argument of the javac task passes the setting to the compiler. property任务使您可以访问环境,然后javac任务bootclasspath参数将设置传递给编译器。

<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. 如果合适,另一个选项是关闭警告 ,而不是打扰bootclasspath。 Something like 就像是

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

But that's likely to expose you to some subtle bugs. 但这可能会让你暴露出一些微妙的错误。

It's worth noticing that variable JAVA5_BOOTCLASSES should contain all needed libraries not just rt.jar. 值得注意的是,变量JAVA5_BOOTCLASSES应该包含所有需要的库,而不仅仅是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: 在我的情况下,它也是jce.jar所以在* nix环境中使用这个简单的代码段来设置这个变量是很好的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM