为Eclipse编译器与Maven安装Java 6的注解处理配置 [英] Setup Java 6 annotation processing configuration for eclipse compiler with maven

查看:225
本文介绍了为Eclipse编译器与Maven安装Java 6的注解处理配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是设置的最佳方式对Java 6的注解处理器的Eclipse项目编译器配置?

我的解决方案是建立在 org.eclipse.jdt.apt.core。preFS factorypath 手动文件。这是一个有点麻烦:


  • 参考处理器罐子在factorypath文件

  • 配置Eclipse的注解处理器的输出目录(org.eclipse.jdt.apt.genSrcDir 地产 org.eclipse.jdt.apt.core 。preFS

  • 添加日食注释处理器输出目录作为源文件夹

一个问题是,日食产生的来源将与Maven进行编译。只有行家干净编译是可靠的,因为它消除了Eclipse生成的源文件。 (Eclipse和javac的生成源文件可能是不同步的。)

时有更好的解决办法来配置不maven的日食发生在Maven的源路径源文件?

<项目>
  <性状>
    &LT; eclipse.generated.src&GT; $ {} project.build.directory /eclipse</eclipse.generated.src>
  &LT; /性状&gt;
  &LT;建立&GT;
      &LT;&插件GT;
            &LT;的groupId方式&gt;组织codehaus.mojo&LT; /的groupId&GT;
            &LT;&的artifactId GT;建立辅助-Maven的插件&LT; / artifactId的&GT;
            &LT;&版GT; 1.4 LT; /版本&GT;
            &LT;&执行GT;
                &LT;执行与GT;
                  &LT; ID&gt;添加源&LT; / ID&GT;
                  &LT;阶段&gt;生成来源和LT; /阶段&gt;
                  &LT;目标&GT; &LT;目标&gt;添加源&LT; /目标&GT; &LT; /目标&GT;
                  &LT;结构&gt;
                      &LT;来源和GT;
                        &lt;信源&GT; $ {eclipse.generated.src}&LT; /源&GT;
                      &LT; /来源&GT;
                    &LT; /结构&gt;
              &LT; /执行&GT;
            &LT; /处决&GT;
          &LT; /插件&GT;
      &LT;&插件GT;
        &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
        &LT;&的artifactId GT; Maven的Eclipse的插件&LT; / artifactId的&GT;
        &LT;结构&gt;
          &LT; additionalConfig&GT;
            &LT;文件&gt; &LT;名称&gt;&.factorypath LT; /名称&gt;
        &lt;内容&GT;&LT;![CDATA [&LT; factorypath&GT;
  &LT; factorypathentry样=VARJA​​RID =M2_REPO /处理器/ processor.jar启用=真runInBatchMode =FALSE/&GT;
  &LT; / factorypath&GT;
  ]]&GT; &LT; /内容&GT;
            &LT; /文件&gt;
            &LT;文件&gt;
              &LT;名称&gt; .settings / org.eclipse.jdt.apt.core preFS和LT; /名称&gt;
        &lt;内容&GT;&LT;![CDATA [
  日食。preferences.version = 1
  org.eclipse.jdt.apt.aptEnabled =真
  org.eclipse.jdt.apt.genSrcDir = $ {} eclipse.generated.src
  org.eclipse.jdt.apt.reconcileEnabled =真
   ]]&GT; &LT; /内容&GT;
            &LT; /文件&gt;
          &LT; / additionalConfig&GT;
        &LT; /结构&gt;
      &LT; /插件&GT;
    &LT; /插件&GT;
  &LT; /构建&GT;
&LT; /项目&GT;


解决方案

更​​新:您可以尝试使用的的apt-Maven的插件。目前,它提供了三个目标:

您可以配置目标作为构建的一部分运行如下:

&LT;建立&GT;
  ...
  &LT;&插件GT;
    ...
    &LT;&插件GT;
      &LT;的groupId方式&gt;组织codehaus.mojo&LT; /的groupId&GT;
      &LT;&的artifactId GT;的apt-Maven的插件&LT; / artifactId的&GT;
      &LT;&版GT; 1.0-α-2'; /版本&GT;
      &LT;&执行GT;
        &LT;执行与GT;
          &LT;目标&GT;
            &LT;&目标GT;处理&LT; /目标&GT;
            &LT;&目标GT;测试过程和LT; /目标&GT;
          &LT; /目标&GT;
        &LT; /执行&GT;
      &LT; /处决&GT;
    &LT; /插件&GT;
    ...
  &LT; /插件&GT;
  ...
&LT; /构建&GT;

默认情况下,输出目录设置为 $ {} project.build.directory /生成的来源/公寓

有一个打开吉拉对编译器插件添加APT的支持对于Java 6中,你可以去投赞成票,如果这是你想在未来的版本中看到的东西。

What's the best way to setup the eclipse project compiler configuration for Java 6 annotation processors?

My solution is to setup the org.eclipse.jdt.apt.core.prefs and factorypath files manually. This is a bit cumbersome:

  • Reference the processor jar in the factorypath file
  • Configure the eclipse annotation processor output directory (org.eclipse.jdt.apt.genSrcDir property in org.eclipse.jdt.apt.core.prefs)
  • Add the eclipse annotation processor output directory as source folder

One problem is that eclipse generated sources will be compiled with maven. Only maven clean compile is reliable as it removes the eclipse generated source files. (Eclipse and javac generated source files could be out of sync.)

Is there are better solution to configure maven without eclipse generated source files at the maven source path?

<project>
  <properties>
    <eclipse.generated.src>${project.build.directory}/eclipse</eclipse.generated.src>
  </properties>
  <build>
      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals> <goal>add-source</goal> </goals>
                  <configuration>
                      <sources>
                        <source>${eclipse.generated.src}</source>
                      </sources>
                    </configuration>
              </execution>
            </executions>
          </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <additionalConfig>
            <file> <name>.factorypath</name>
        <content><![CDATA[<factorypath>
  <factorypathentry kind="VARJAR" id="M2_REPO/processor/processor.jar" enabled="true" runInBatchMode="false"/>
  </factorypath>
  ]]>      </content>
            </file>
            <file>
              <name>.settings/org.eclipse.jdt.apt.core.prefs</name>
        <content><![CDATA[
  eclipse.preferences.version=1
  org.eclipse.jdt.apt.aptEnabled=true
  org.eclipse.jdt.apt.genSrcDir=${eclipse.generated.src}
  org.eclipse.jdt.apt.reconcileEnabled=true
   ]]>     </content>
            </file>
          </additionalConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

解决方案

Update: You could try using the apt-maven-plugin. It currently provides three goals:

You can configure the goals to run as part of your build as follows:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>apt-maven-plugin</artifactId>
      <version>1.0-alpha-2</version>
      <executions>
        <execution>
          <goals>
            <goal>process</goal>
            <goal>test-process</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

By default the output directory is set to ${project.build.directory}/generated-sources/apt,

There is an open Jira against the compiler plugin to add APT support for Java 6, you can go and vote for it if this is something you want to to see in future versions.

这篇关于为Eclipse编译器与Maven安装Java 6的注解处理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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