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

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

问题描述

所以伙计们,

我正在尝试使用Ant和终端上的Javac Cross编译。在本地和集成环境中,我在最基本的问题上遇到了同样的问题。

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终端运行它(以及我在windows上的cygwin上运行)和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.

推荐答案

你不能拥有更新版的sou rce和较低版本的目标。
例如,在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的值为 - 的值 - 来源。

  • If -source is not specified, the value of -target is 1.7
  • If -source is 1.2, the value of -target is 1.4
  • If -source is 1.3, the value of -target is 1.4
  • If -source is 1.5, the value of -target is 1.7
  • If -source is 1.6, the value of -target is 1.7
  • For all other values of -source, the value of -target is the value of -source.

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

For more info refer to http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

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

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