Javac 与 1.7 交叉编译 [英] Javac Cross-Compilation with 1.7

查看:32
本文介绍了Javac 与 1.7 交叉编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我正在尝试使用 Ant 和终端进行 Javac 交叉编译.在本地和集成环境中,我在非常基本的问题上遇到了同样的问题.

I'm trying to play a bit with Javac Cross compilation with Ant and on terminal. Locally and on an integration environment and i'm having the same problem on the very basic problem.

我在 linux 终端(以及我的 cygwin 上的 windows 和 cmd)中运行它:

I run this in the linux terminal (and also on my cygwin on windows and the cmd):

 javac -target 1.6 -source 1.7 -bootclasspath /usr/java/jdk1.6.0_27/jre/lib/rt.jar Main.java

使用 Main.java 和 System.out.println.

with Main.java with nothing other than a System.out.println.

javac -version ==> javac 1.7.0_11

我收到错误消息:

javac: source release 1.7 requires target release 1.7

我在本地 Windows 机器上的配置大致相同,结果完全相同.

I have roughly the same configuration on my local windows machine with the exact same results.

我的理解是,交叉编译就是使用更高版本的 jdk 编译一些与更高版本 jdk 兼容的源代码,但传递的目标版本的 rt.jar 应该是较低的.

It was my understanding that cross compilation is all about compiling some source code that is compatible with a higher version jdk using that higher version of jdk, but passing the rt.jar of the target version that is supposedly lower.

如果目标和源相同,则有效.

if target and source are the same, it worked.

target=1.7 and source=1.7 workd fine

target=1.6 and source=1.6 worked just fine

但是我想要交叉编译,那么我做错了什么?

but i want cross-compilation, so what is it that i'm doing wrong?

感谢我能得到的所有帮助,并提前致谢.

I appreciate all the help I could get and thanks in advance.

推荐答案

您不能拥有较新版本的源和较低版本的目标.例如,在 Java 5 中,该语言添加了许多新功能,例如泛型、自动装箱,您不能指望 JVM 1.4 能够理解它.因此,您必须告诉编译器您的源代码是 Java 1.4 源代码.这解释了您的结果.

You cannot have a newer version of source and lower version of target. For example, In Java 5, a number of new features were added to the language, such as generics, autoboxing and you cannot expect a JVM 1.4 to understand it. So, you must tell the compiler that your source code is Java 1.4 source code. This explains the results you have.

-target 的默认值取决于 -source 的值:

The default for -target depends on the value of -source:

  • 如果不指定 -source,则 -target 的值为 1.7
  • 如果 -source 为 1.2,则 -target 的值为 1.4
  • 如果 -source 为 1.3,则 -target 的值为 1.4
  • 如果 -source 为 1.5,则 -target 的值为 1.7
  • 如果 -source 为 1.6,则 -target 的值为 1.7
  • 对于 -source 的所有其他值,-target 的值就是 -source 的值.

有关更多信息,请参阅http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

这篇关于Javac 与 1.7 交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆