我们可以使用jdk7 javac将java7特性的代码编译成java6字节码 [英] Can we use jdk7 javac to compile code with java7 features into java6 bytecode

查看:208
本文介绍了我们可以使用jdk7 javac将java7特性的代码编译成java6字节码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑一个java项目是否可以生成2个jar:一个用于java7,一个用于java6,是的,源代码可能会使用一些java7新功能。

I was considering if a java project could produce 2 jars: one for java7 and one for java6, yes, the source code might use some some java7 new features.

所以要生成java6 jar,命令行就像:

so to generate the java6 jar, the command line would be like:

javac -target 1.6 -bootclasspath jdk1.6.0\lib\rt.jar -extdirs "" MyApp.java

不幸的是,
它只是发出错误:

Unfortunately, It simply emits an error:

javac: target release 1.6 conflicts with default source release 1.7

根据这个文件,它应该可以用于jdk6 vs jdk5,任何人都知道为什么它在jdk7 vs jdk6中不起作用?我做错了什么,或者只是官方不支持?

According to this document, it should be possible for jdk6 vs jdk5, anybody knows why it doesn't work in jdk7 vs jdk6? did I do something wrong, or is it just officially not supported?

谢谢。

推荐答案

AFAIK,源和目标必须相同。即使对于Java 6.唯一的例外是源可以是1.1和目标1.0。

AFAIK, the source and target have to be the same. Even for Java 6. The only exception is the source can be 1.1 and the target 1.0.

鉴于最新的JVM for Java 6和JVM之间的JVM差异很小。 Java 7,我建议你考虑升级。 Java 6将于2012年11月完成(免费)服务,从现在开始三个月......

Given there is little difference in the JVM between the latest JVM for Java 6 and Java 7, I suggest you consider upgrading. Also Java 6 will be, End Of (free) Service in Nov 2012, which three months from now...

这篇关于我们可以使用jdk7 javac将java7特性的代码编译成java6字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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