在maven构建中使用Eclipse Java Compiler(ecj) [英] Using Eclipse Java Compiler (ecj) in maven builds

查看:1610
本文介绍了在maven构建中使用Eclipse Java Compiler(ecj)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipse使用自己的编译器(ECJ)来编译Java代码。调试使用Eclipse编译的程序更容易,因为可以立即应用简单的代码更改(通过热代码替换)。另一方面,Maven(默认情况下)使用Maven。 oracle JDK,它生成不同的字节代码,防止Eclipse调试会话中的热代码替换。



所以我想使用Eclipse ECJ编译器与我的maven构建,如果我计划调试程序。一个方便的方式就是ecj配置文件:




  • 编译版本

      $ mvn package 


  • 编译快照与启用热代码替换

      $ mvn -P ecj包




此外,配置文件激活可以在 settings.xml 甚至Eclipse项目属性。



我的问题是:


  1. 这是

  2. 如何配置?

  3. 可以使用maven工具链吗?


解决方案

可以更改 javac 编译器://maven.apache.org/plugins/maven-compiler-plugin/rel =nofollow noreferrer> maven-compi LER-插件 。 Eclipse编译器捆绑在工件中 plexus-编译器eclipse ,它通过将 eclipse 设置为 compilerId 属性的/plu​​gins/maven-compiler-plugin/compile-mojo.html#compilerId > maven-compiler-plugin 。



如果要为自定义配置文件,您可以进行以下配置:

 < profile> 
< id> ecj< / id>
< build>
< plugins>
< plugin>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.6.0< / version>
< configuration>
< compilerId> eclipse< / compilerId>
< / configuration>
<依赖关系>
<依赖关系>
< groupId> org.codehaus.plexus< / groupId>
< artifactId> plexus-compiler-eclipse< / artifactId>
< version> 2.8.1< / version>
< / dependency>
< / dependencies>
< / plugin>
< / plugins>
< / build>
< / profile>

该插件维护在 plexus-compiler GitHub存储库。版本2.8.1 使用JDT的3.11.1.v20150902-1521 ,尽管您可以通过在 org.eclipse.tycho:org.eclipse.jdt.core 在Plexus编译器依赖之后。


Eclipse uses it's own compiler (ECJ) to compile Java code. Debugging a program compiled with Eclipse is easier, because simple code changes can be applied instantly (by the hot code replacement).

Maven on the other hand uses (by default) oracle JDK, that generates different byte code preventing hot code replacement in a Eclipse debug session.

So I would like to use Eclipse ECJ compiler with my maven build, if I plan to debug the program. A convenient way for me would be a "ecj" profile:

  • Compile release

    $ mvn package
    

  • Compile snapshot with enabled hot code replacement

    $ mvn -P ecj package
    

Also the profile activation can be specified in settings.xml or even Eclipse project properties.

My questions are:

  1. Is this the right way to go?
  2. How this can be configured?
  3. Can maven toolchain be used for this?

解决方案

It is possible to change the default javac compiler that is used by the maven-compiler-plugin. The Eclipse compiler is bundled in the artifact plexus-compiler-eclipse and it is declared by setting eclipse to the compilerId attribute of the maven-compiler-plugin.

If you want to activate this change for a custom profile, you could have the following configuration:

<profile>
  <id>ecj</id>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.0</version>
        <configuration>
          <compilerId>eclipse</compilerId>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-eclipse</artifactId>
            <version>2.8.1</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</profile>

The plugin is maintained in the plexus-compiler GitHub repository. Version 2.8.1 uses 3.11.1.v20150902-1521 of JDT, although you could use your own version by adding a dependency on org.eclipse.tycho:org.eclipse.jdt.core after the Plexus Compiler dependency.

这篇关于在maven构建中使用Eclipse Java Compiler(ecj)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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