设置蚂蚁引导类路径:JDK 1.7 有一个新的 javac 警告,用于设置没有引导类路径的旧源
如何结合-source 1.5 -target 1.5 设置ant bootclasspath?
How do I set the ant bootclasspath in conjunction with -source 1.5 -target 1.5?
这怎么可能不是 1.5 JDK 的硬编码路径?是否可以将环境变量设置为 bootclasspath 类似于如何从 ant 中使用 JAVA_HOME?
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?
理想情况下,我想做一些事情,例如设置环境变量或将参数传递给 ant.
Ideally I would like to do something like set an environment variable or pass an argument to ant.
以下说明了如何从环境变量中获取 Java 5 引导类位置,然后使用它.
Here's an illustration of how you might fetch the Java 5 boot classes location from an environment variable, then use it.
首先,设置环境变量——比如JAVA5_BOOTCLASSES
.property
任务 使您可以访问环境,然后是 javac
的 bootclasspath
参数任务将设置传递给编译器.
First, set the environment variable - say 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 environment="env" />
<property name="java5.boot.classpath" value="${env.JAVA5_BOOTCLASSES}" />
<javac source="1.5" target="1.5"
bootclasspath="${java5.boot.classpath}"
...
/>
请注意,如果未设置环境变量,Ant 将忽略它并继续执行 - 因此编译器将回退到默认引导类路径.
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.
如果合适,另一种选择是关闭警告,不要理会引导类路径.类似的东西
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.