本文介绍了Eclipse的火星:ANT不支持JDK 1.6了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用JDK6在Eclipse中调用火星Ant脚本(运行方式> Ant构建...> JRE>独立JRE),我得到以下错误消息:

When I use JDK6 for calling an ANT script in Eclipse Mars (Run as > Ant Build ... > JRE > Separate JRE), I get following error message:

问题发生: JRE版本低于1.7,不支持

这是唯一的错误或故意?我找不到在Eclipse中对应的bug报告。所以Eclipse的下降Java 6的支持ANT?!

Is this only a bug or intentionally? I can't find a corresponding bug report at Eclipse. So Eclipse dropped Java 6 support for ANT?!


  • 截图:

  • 截图:

  • Screenshot: Choosing JDK 1.6 as Runtime JRE for ANT
  • Screenshot: Error when executing ANT script

推荐答案

我们固定的自定义ANT插件的问题。这是一个替代火星捆绑的ANT插件。原来的插件不支持Java< 7,因为它是用Java 7的语法编写上面还有Java版本的支票。这是很容易更换java7目录语法与> = 5兼容,并除去Java 7的检查。

We fixed the problem with a custom ANT plugin. It's a replacement of the Mars bundled ANT plugin. The original plugin didn't support Java < 7 because it was written with Java 7 syntax and it had a check for Java version. It was easy to replace Java7 syntax to be compatible with >= 5 and to remove the Java 7 check.

这两个语法问题是:


  • 钻石运营商,例如列表与LT;为MyObject&GT;名单=新的ArrayList&LT;&GT;();

  • 尝试-与资源,例如尝试(InputStream的流= createInputStream()){...}

  • Diamond operator, e.g. List<MyObject> list = new ArrayList<>();
  • try-with-resources, e.g. try (InputStream stream = createInputStream()) { ...}

有关钻石经营者向后兼容性:

Backwards compatibility for Diamond operator:

List<MyObject> list = new ArrayList<MyObject>();

和尝试,具有资源:

and for try-with-resources:

InputStream stream;

try
{
  ...
}
finally
{
   stream.close();
}

我们替换我们的自定义插件捆绑的插件后,有可能启动一个定制的JRE一个Ant任务,像往常一样。

After we replaced the bundled plugin with our custom plugin, it was possible to start an ANT task with a custom JRE, as usual.

这是可能的创建与Eclipse的Git代码库的原始代码自己的Ant插件:的(使用标记ID:I20150430-1445),或者用我的pre-编译包:

It's possible to create your own ANT plugin with original sources from Eclipse git repository: http://git.eclipse.org/c/platform/eclipse.platform.git/refs/tags (use Tag ID: I20150430-1445) or to use my pre-compiled bundle: Eclipse Mars ANT plugin with support for Java < 7

安装很简单:


  • 下载zip压缩包*,其中的内容解压到&lt; eclipse_dir方式&gt; /插件

  • 先从参数-clean日食(仅一次)

  • 配置JRE6您的Ant任务,通过的外部材料工具配置...

  • Download the zip archive*, extract the content to <eclipse_dir>/plugins.
  • Start eclipse with parameter -clean (only once)
  • Configure JRE6 for your ANT task, via Externals Tool configuration...

关于解决方案的更多细节rel=\"nofollow\">这个博客帖子。

More details about the solution can be found in this blog post.

这篇关于Eclipse的火星:ANT不支持JDK 1.6了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:14