Javac Cross-Compilation with 1.7

a 夏天 提交于 2019-11-30 08:20:21
vinay

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.

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

  • 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.

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

This is a limit in javac. Note that you could get away with just specifying "-target" (and not -source) in older versions of javac. You might still be able to.

You may want to consider using the Eclipse Java Compiler (ecj) which is available as a standalone compiler, as a maven plugin and which also can be used by the javac task in ant scripts.

See http://help.eclipse.org/indigo/topic/org.eclipse.jdt.doc.user/tasks/task-using_batch_compiler.htm for details.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!