如何编译.java支持旧版本的java? [英] How do i compile a .java with support for older versions of java?
问题描述
我想将我的.java(几个)编译成一个.jar,它们至少与1.6和更新的,最好是1.5和更新版本的java兼容。 (我有1.7.0_5)
I want to compile my .java's (several) into one .jar that are compatible with at least 1.6 and newer, preferrably 1.5 and newer versions of java. (I have 1.7.0_5)
推荐答案
是的,你可以在编译时设置编译器的版本。并将您的java代码编译为旧版本的java。
Yes, you can set the version of compiler at compile time. And compile your java code into old versions of java.
从Oracle文章:
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
From Oracle article : http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html
交叉编译示例
这里我们使用javac来编译代码在1.4 VM上运行。
Here we use javac to compile code that will run on a 1.4 VM.
% javac -target 1.4 -bootclasspath jdk1.4.2/lib/classes.zip \
-extdirs "" OldCode.java
您可能还需要以下参数来指定版本您的代码。
You might also need following parameter to set denote the version of your code.
-source release
指定接受的源代码的版本。
-Specifies the version of source code accepted.
这篇关于如何编译.java支持旧版本的java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!