哪个JDK的发行版可以运行`javac -source 1.6 -target 1.5`? [英] Which JDK's distributions can run `javac -source 1.6 -target 1.5`?

查看:165
本文介绍了哪个JDK的发行版可以运行`javac -source 1.6 -target 1.5`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:请对交叉编译的所有风险进行评论。谢谢。

NOTE: Please do not comment on all the perils of cross-compiling. Thank you.

我有一种情况需要为Java 5 JVM编译Java 6源码(需要确保JAX-WS的使用是正确的)。以前我们用ant ant脚本(显然可以)这样做了,但是在迁移到Maven之后我们发现它最终以javac抱怨:

I have a situation where we need to have Java 6 source compiled for a Java 5 JVM (to be sure that JAX-WS usage is correct). Previously we have done this with ant ant script (which apparently can), but after migrating to Maven we have found that it ends up with javac complaining:

$ javac -source 1.6 -target 1.5
javac: source release 1.6 requires target release 1.6

是否有用于Linux的任何 Java发行版(Ubuntu 11.10,x86),其中javac可以执行此操作?

Is there any Java distribution for Linux (Ubuntu 11.10, x86) where the javac can do this?

编辑:似乎没有,因为javac的限制是相同的。解决方案(这使得需要消失)是从默认的javac编译器更改为maven-compiler-plugin中的eclipse编译器。

It appears not, as the limitation is in javac which is the same. The solution (which made this need go away) was to change from the default javac compiler to the eclipse compiler in maven-compiler-plugin.

编辑:我发现Eclipse编译器为javadoc实用程序不同意的匿名内部类生成字节代码。我正在为此问题准备一份错误报告。

I've found that the Eclipse compiler generates byte code for anonymous inner classes that the javadoc utility disagrees with. I am preparing a bug report for this issue.

推荐答案

根据文档( Java 5 Java 6 ),当您按照Cross-Compilation Example

According to the documentation (Java 5, Java 6), the Oracle SDK should be able to do this when you follow the instructions in the Cross-Compilation Example.

Java 6应支持1.3到1.6之间的任何版本 -target ;当你在源代码中使用泛型和其他兼容功能时,它没有说明会发生什么。编译器能够剥离它们。

Java 6 should support any version between 1.3 to 1.6 as -target; it doesn't say anything what happens when you use generics and other "compatible" features in the source. The compiler should be able to strip them.

游戏中的另一个罪魁祸首可能是 javac 编译器可能能够处理这组参数,但命令行工具可能会冒犯。

Another culprit in the game might be javac: The compiler might be able to handle this set of arguments but the command line tool might take offense.

在这种情况下,使用 Java Compiler API编写自己的命令行。这可能会导致你无法实现的一些技巧。

In this case, write your own command line using the Java Compiler API. That might allow to pull of some tricks that you can't achieve otherwise.

你也可以尝试Eclipse编译器(参见使用批处理编译器

You can also try the Eclipse compiler (see "Using the batch compiler").

由于Java的工作方式,这可能会失败:只要X <= Y,Java X代码就可以在Java Y上运行。因此,虽然您可以轻松地为Java 6 VM编译Java 1.4代码,反转并不总是正确的。

This might fail because of how Java works: Java X code can run on Java Y as long as X <= Y. So while you can easily compile Java 1.4 code for a Java 6 VM, the reverse is not always true.

如果其他一切都失败了,写一个预处理器来读取源并删除不支持的元素(比如 @Override on interfaces)。只要您使用Java 6编译带有注释的代码,转换后的代码也应该是安全的(除非您的代码剥离器有错误...)

If everything else fails, write a preprocessor that reads the source and strips unsupported elements (like @Override on interfaces). As long as you compile the code with the annotations once in a while with Java 6, the converted code should be safe as well (unless your code stripper has a bug ...)

这篇关于哪个JDK的发行版可以运行`javac -source 1.6 -target 1.5`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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