本文介绍了为maven为eclipse编译器设置Java 6注释处理配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的解决方案是设置 org.eclipse .jdt.apt.core.prefs factorypath 文件。这有点麻烦:




  • 参考factorypath文件中的处理器jar

  • 配置日食注释处理器输出目录(org.eclipse.jdt.apt.genSrcDir 属性 org.eclipse.jdt.apt.core.prefs
  • 将eclipse注解处理器输出目录添加为源文件夹



是eclipse生成的源将使用maven编译。只有 maven clean compile 是可靠的,因为它会删除eclipse生成的源文件。 (Eclipse和javac生成的源文件可能不同步)



有没有更好的解决方案配置maven没有eclipse生成源文件在maven源路径? p>

 < project> 
<属性>
< 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>
<执行>
< execution>
< id> add-source< / id>
< phase> generate-sources< / phase>
< goals> <目标>添加源和LT; /目标> < /目标>
< 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> <名称>&.factorypath LT; /名称>
< content><![CDATA [< factorypath>
< factorypathentry kind =VARJARid =M2_REPO / processor / processor.jarenabled =truerunInBatchMode =false/>
< / factorypath>
]]> < /内容>
< / 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
]]> < /内容>
< / file>
< / additionalConfig>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>


解决方案

更新:您可以尝试使用。它目前提供三个目标:




  • 在项目源上执行apt。

  • 在项目测试源上执行apt。

  • apt:eclipse 生成Eclipse文件以进行适应集成。



您可以将目标配置为您的构建的一部分,如下所示:

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

默认情况下,输出目录设置为 $ {project.build.directory } / generated-sources / apt



有一个针对编译器插件添加APT对Java 6的支持,如果这是您希望在将来的版本中看到的话,您可以去投票。 / p>

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.

这篇关于为maven为eclipse编译器设置Java 6注释处理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:31