【发布时间】:2010-12-01 15:24:19
【问题描述】:
为 Java 6 注释处理器设置 eclipse 项目编译器配置的最佳方法是什么?
我的解决方案是手动设置org.eclipse.jdt.apt.core.prefs 和factorypath 文件。这有点麻烦:
- 在 factorypath 文件中引用处理器 jar
- 在
org.eclipse.jdt.apt.core.prefs中配置eclipse注解处理器输出目录(org.eclipse.jdt.apt.genSrcDir属性) - 将 eclipse 注释处理器输出目录添加为源文件夹
一个问题是eclipse生成的源码会用maven编译。只有maven 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>
【问题讨论】:
标签: java eclipse maven-2 annotations javac