为 Java 6 注释处理器设置 eclipse 项目编译器配置的最佳方法是什么?
我的解决方案是手动设置org.eclipse.jdt.apt.core.prefs
和文件。factorypath
这有点麻烦:
- 引用 factorypath 文件中的处理器 jar
- 在)中配置 eclipse 注释处理器输出目录
(org.eclipse.jdt.apt.genSrcDir
属性org.eclipse.jdt.apt.core.prefs
- 将 eclipse 注释处理器输出目录添加为源文件夹
一个问题是 Eclipse 生成的源代码将使用 maven 进行编译。Onlymaven clean compile
是可靠的,因为它删除了 eclipse 生成的源文件。(Eclipse 和 javac 生成的源文件可能不同步。)
是否有更好的解决方案来配置 maven 而无需在 maven 源路径中生成 eclipse 生成的源文件?
<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>