从 _within_ build.xml 中完全指定 Eclipse 编译器 [英] Specifying the Eclipse compiler completely from _within_ build.xml

查看:21
本文介绍了从 _within_ build.xml 中完全指定 Eclipse 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个实验,我们希望在 Java 6 的运行时版本而不是 JDK 上使用 Eclipse java 编译器(从 eclipse.org 下载的 ecj-3.5.jar)构建我们的产品,据我所知,它是一个将此 jar 添加到 ant 类路径,并将 build.compiler 属性设置为指向适配器.

As an experiment we want to build our products using the Eclipse java compiler (ecj-3.5.jar downloaded from eclipse.org) on the runtime version of Java 6 instead of the JDK, and as I understand it, it is a matter of adding this jar to the ant classpath, and setting the build.compiler property to point to the adapter.

通过包含

<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />

在我的 build.xml 中并使用 JRE 调用 ant,我得到了无法找到适配器的预期错误,通过将 ecj-3.5.jar 添加到 Eclipse 面板中的类路径,我可以按预期编译我的代码.我相信现代蚂蚁的命令行中的-lib foo.jar"可以使用相同的功能.

in my build.xml and invoking ant with a JRE, I get the expected error that the adapter cannot be found, and by adding ecj-3.5.jar to the classpath in the Eclipse panel I can compile my code as expected. I believe the same functionality to be available with "-lib foo.jar" from the command line with modern ants.

现在,我想从 within build.xml 中指定我希望在我的类路径上的 ecj-3.5.jar 满足与上述相同的要求.我们已经可以用蚂蚁任务来做到这一点,所以我相信这是可能的.

Now, I want to specify from within build.xml that I want ecj-3.5.jar on my classpath satisfying the same as above. We can already do this with ant tasks, so I believe it is possible.

所以问题是:我如何添加到 javac 使用的类路径中,以便在 build.xml 中定位编译器only?

So the question is: How can I add to the classpath used by javac to locate the compiler only from within build.xml?

似乎即将发布的 ant4eclipse 1.0 包含 Eclipse 编译器(这是我想要使用它的目的),因此通过升级到该编译器(从 0.5 开始)应该可以解决我们遇到的问题.

It appears that the upcoming ant4eclipse 1.0 includes the Eclipse compiler (which is what I wanted to use this for), so by upgrading to that (from 0.5) should solve the problem we have.

2010 年 9 月 24 日:Ant4Eclipse 仍处于 M4 阶段,未指明何时发布.

2010-09-24: Ant4Eclipse is still at M4 without indication of when the release will happen.

2011-12-01:我们现在已经从 ant 迁移到了 maven.build.xml 脚本遇到了复杂性问题,需要一种新的方法.任何需要选择做什么的人 - 除了琐碎的项目外,不要走 ant4eclipse 的道路.

2011-12-01: We have now migrated from ant to maven. The build.xml scripts hit the complexity wall and a fresh approach was needed. Anyone needing to choose what to do - do not go the ant4eclipse path except for trivial projects.

2012-11-30:一年过去了,maven 的体验还是大多不错.思维方式有很多怪癖和变化,但大多数在上下文中都有意义.Maven 可以轻松地为单个项目指定编译器级别.我们正在考虑使用 ecj 而不是 javac(出于多种原因),但在大多数情况下,javac 运行良好.

2012-11-30: A year later, the maven experience is still mostly good. There is a lot of quirks and changes in mindset but most make sense in the context. Maven can specify the compiler level on individual projects easily. We are looking into using ecj instead of javac (for several reasons) but for most purposes javac works nicely.

推荐答案

一种方法是在使用 javac 时指定对 componentdef 的引用.

One way is to specify a reference to a componentdef when using javac.

<componentdef name="ecj" 
              classname="org.eclipse.jdt.core.JDTCompilerAdapter" 
              classpath="ecj-3.7.1.jar" />

<javac ....>
  <ecj/>
</javac>

另一个选项是设置 build.compiler 或 javac 的编译器属性,然后为 javac 指定一个编译器类路径.这是一个类似结构的普通路径,用于保存用于加载编译器适配器的类路径.

Another option is to set build.compiler as you have or the compiler attribute for javac and then specify a compilerclasspath for javac. This is a normal path like structure to hold the classpath for loading your compiler adapter.

<javac compiler="org.eclipse.jdt.core.JDTCompilerAdapter" ....>
  <compilerclasspath>
     ...
  </compilerclasspath>
</javac>

有关详细信息,请参阅 Ant 手册中的 javac task 文档.请注意,这两种解决方案仅适用于 Ant 1.8 及更高版本.

See the javac task documentation in the Ant manual for more details. Note that both these both solutions only work from Ant 1.8 onwards.

这篇关于从 _within_ build.xml 中完全指定 Eclipse 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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