问题描述
我维护一个Java应用程序,我总是在分发之前使用JDK 1.6编译它,因为这是我的应用程序所需的最低版本 - 我不使用任何更新的功能。我没有看到在更高版本中编译它的意义,或者较旧的JRE将无法运行它(即Mac OSX上使用Java 1.6的用户)。
I maintain a Java application which I have always compiled using JDK 1.6 before distributing it as this is the minimum version that my application requires - I don't use any newer features. I don't see the point of compiling it in a later version or older JREs won't be able to run it (i.e. users on Mac OSX which use Java 1.6).
现在,最近关于Java的新闻安全性以及JDK更高版本中的错误修复,使用以下语法使用最新的JDK进行交叉编译更好:
Now, with security in the news recently with respect to Java and with bug fixes in later versions of the JDK, is it better to cross compile it using the latest JDK available using the following syntax:
javac -Xlint -source 1.6 -target 1.6 -bootclasspath jre6/lib/rt.jar MyClass.java
这会产生一个在JRE 1.6下运行良好的Class文件,但是首先使用JDK 1.6有什么好处?我是否正在利用新JDK中的任何优化,或者我生成相同的字节码?
This produces a Class file which runs fine under JRE 1.6, but are there any benefits over using JDK 1.6 in the first place? Am I taking advantage of any optimisations in newer JDKs or am I generating identical bytecode?
推荐答案
您应该考虑以下几点:
There are several points you should consider:
- Tools shipped with your JDK get updated. There maybe new tools for developing java application, e.g. at some point java VisualVM was added to the JDK.
看一下这个列表,我认为使用当前JDK的优点超过了使用旧版本的优点。
Looking at that list i think the pros of using a current JDK outweighs the pros of using an old one.
编辑:
我调查了一下,我建议您现在安装适合您目标版本的JDK。由于bootstrap / ext类路径,在交叉编译时无论如何都需要JDK。请参阅了解更多信息。该站点还指出不同JDK之间的编译存在差异(从倒数第二段开始),并建议使用与目标版本相关的JDK(最后一段)。也可能是。
EDIT: I investigated a little bit and i suggest now that you install the JDK which suits your target version. You need the JDK anyway when you are cross compiling because of the bootstrap/ext classpath. See How to cross-compile for older platform versions for further information. This site also states that there are differences in compilation between different JDKs (second to last paragraph) and suggests to use the JDK relevant to your target version (last paragraph). Also relevant may be the javac documentation.
这篇关于Java交叉编译 - 最新JDK的优点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!