为 Java 6 注释处理器设置 eclipse 项目编译器配置的最佳方法是什么?
我的解决方案是设置org.eclipse.jdt.apt.core.prefs
and factorypath
手动文件。这有点麻烦:
- 在工厂路径文件中引用处理器 jar
- 配置eclipse注释处理器输出目录
(org.eclipse.jdt.apt.genSrcDir
财产在org.eclipse.jdt.apt.core.prefs
)
- 添加 Eclipse 注释处理器输出目录作为源文件夹
一个问题是 eclipse 生成的源代码将使用 maven 进行编译。仅有的maven clean compile
是可靠的,因为它删除了 eclipse 生成的源文件。 (Eclipse 和 javac 生成的源文件可能不同步。)
是否有更好的解决方案来配置 Maven,而无需 Eclipse 在 Maven 源路径生成源文件?
<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>
更新:您可以尝试使用apt-maven-插件 http://mojo.codehaus.org/apt-maven-plugin/。目前它提供了三个目标:
-
apt-进程 http://mojo.codehaus.org/apt-maven-plugin/process-mojo.html在项目源上执行 apt。
-
apt:测试过程 http://mojo.codehaus.org/apt-maven-plugin/test-process-mojo.html在项目测试源上执行 apt。
-
适合:日食 http://mojo.codehaus.org/apt-maven-plugin/eclipse-mojo.html生成 Eclipse 文件以进行 apt 集成。
您可以将目标配置为作为构建的一部分运行,如下所示:
<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>
默认情况下,输出目录设置为${project.build.directory}/generated-sources/apt
,
有一个打开吉拉 http://jira.codehaus.org/browse/MCOMPILER-75反对编译器插件添加对 Java 6 的 APT 支持,如果你想在未来的版本中看到这一点,你可以去投票。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)