目前我通过
在eclipse中为项目生成带注释处理器的文件Right click on project > Run As > Maven Clean
Right click on project > Run As > Maven install
这非常耗时。如何设置eclipse以使其在保存时运行注释处理器?
我有“自动构建”功能集但似乎忽略了注释处理器。 BTW我正在使用m2e apt插件“自动配置JDT APT激活”。
答案 0 :(得分:3)
I have annotation processing working in Eclipse for some of my projects; for me, it IS working on save, and I don't have to C:\windows\system32\cmd.exe;
(and it works differently than Maven, as Eclipse runs its own compiler).
I'm also using DECLARE
@WeekColumns VARCHAR(8000) = '',
@sql VARCHAR(8000) = '',
@DeBug BIT = 1; -- change to 0 to execute & 1 to print.
SELECT TOP 52
@WeekColumns = CONCAT(@WeekColumns, ',
[',t.n, '] = SUM(CASE WHEN sa.FiscalWeek = ', t.n, ' THEN sa.SalesExVAT ELSE 0 END)')
FROM
dbo.tfn_Tally(52, 1) t;
SET @sql = CONCAT('
SELECT
sa.BranchNo',
@WeekColumns, '
FROM
dbo.SalesAggregateWeek sa
WHERE
sa.FiscalYear = 2016;')
IF @DeBug = 1
BEGIN
PRINT(@sql);
END;
ELSE
BEGIN
EXEC(@sql);
END;
plugin for this.
As noted above, Eclipse runs its own compiler; that means that its output can differ slightly than Maven's (when you "Right click on project > Run As > Maven Clean / Install" you're invoking Maven, not Eclipse). I'm mentioning this because it is entirely possible that your processors have a problem and work in Maven but not in Eclipse (although most of the time they do produce the same output; I've seen some differences, but very small). I'd keep an eye on Eclipse's error log if I were you (because that's where annotation processing errors are written).
So here is what I suggest:
SELECT
sa.BranchNo,
[1] = SUM(CASE WHEN sa.FiscalWeek = 1 THEN sa.SalesExVAT ELSE 0 END),
[2] = SUM(CASE WHEN sa.FiscalWeek = 2 THEN sa.SalesExVAT ELSE 0 END),
[3] = SUM(CASE WHEN sa.FiscalWeek = 3 THEN sa.SalesExVAT ELSE 0 END),
[4] = SUM(CASE WHEN sa.FiscalWeek = 4 THEN sa.SalesExVAT ELSE 0 END),
[5] = SUM(CASE WHEN sa.FiscalWeek = 5 THEN sa.SalesExVAT ELSE 0 END),
[6] = SUM(CASE WHEN sa.FiscalWeek = 6 THEN sa.SalesExVAT ELSE 0 END),
[7] = SUM(CASE WHEN sa.FiscalWeek = 7 THEN sa.SalesExVAT ELSE 0 END),
[8] = SUM(CASE WHEN sa.FiscalWeek = 8 THEN sa.SalesExVAT ELSE 0 END),
[9] = SUM(CASE WHEN sa.FiscalWeek = 9 THEN sa.SalesExVAT ELSE 0 END),
[10] = SUM(CASE WHEN sa.FiscalWeek = 10 THEN sa.SalesExVAT ELSE 0 END),
[11] = SUM(CASE WHEN sa.FiscalWeek = 11 THEN sa.SalesExVAT ELSE 0 END),
[12] = SUM(CASE WHEN sa.FiscalWeek = 12 THEN sa.SalesExVAT ELSE 0 END),
[13] = SUM(CASE WHEN sa.FiscalWeek = 13 THEN sa.SalesExVAT ELSE 0 END),
[14] = SUM(CASE WHEN sa.FiscalWeek = 14 THEN sa.SalesExVAT ELSE 0 END),
[15] = SUM(CASE WHEN sa.FiscalWeek = 15 THEN sa.SalesExVAT ELSE 0 END),
[16] = SUM(CASE WHEN sa.FiscalWeek = 16 THEN sa.SalesExVAT ELSE 0 END),
[17] = SUM(CASE WHEN sa.FiscalWeek = 17 THEN sa.SalesExVAT ELSE 0 END),
[18] = SUM(CASE WHEN sa.FiscalWeek = 18 THEN sa.SalesExVAT ELSE 0 END),
[19] = SUM(CASE WHEN sa.FiscalWeek = 19 THEN sa.SalesExVAT ELSE 0 END),
[20] = SUM(CASE WHEN sa.FiscalWeek = 20 THEN sa.SalesExVAT ELSE 0 END),
[21] = SUM(CASE WHEN sa.FiscalWeek = 21 THEN sa.SalesExVAT ELSE 0 END),
[22] = SUM(CASE WHEN sa.FiscalWeek = 22 THEN sa.SalesExVAT ELSE 0 END),
[23] = SUM(CASE WHEN sa.FiscalWeek = 23 THEN sa.SalesExVAT ELSE 0 END),
[24] = SUM(CASE WHEN sa.FiscalWeek = 24 THEN sa.SalesExVAT ELSE 0 END),
[25] = SUM(CASE WHEN sa.FiscalWeek = 25 THEN sa.SalesExVAT ELSE 0 END),
[26] = SUM(CASE WHEN sa.FiscalWeek = 26 THEN sa.SalesExVAT ELSE 0 END),
[27] = SUM(CASE WHEN sa.FiscalWeek = 27 THEN sa.SalesExVAT ELSE 0 END),
[28] = SUM(CASE WHEN sa.FiscalWeek = 28 THEN sa.SalesExVAT ELSE 0 END),
[29] = SUM(CASE WHEN sa.FiscalWeek = 29 THEN sa.SalesExVAT ELSE 0 END),
[30] = SUM(CASE WHEN sa.FiscalWeek = 30 THEN sa.SalesExVAT ELSE 0 END),
[31] = SUM(CASE WHEN sa.FiscalWeek = 31 THEN sa.SalesExVAT ELSE 0 END),
[32] = SUM(CASE WHEN sa.FiscalWeek = 32 THEN sa.SalesExVAT ELSE 0 END),
[33] = SUM(CASE WHEN sa.FiscalWeek = 33 THEN sa.SalesExVAT ELSE 0 END),
[34] = SUM(CASE WHEN sa.FiscalWeek = 34 THEN sa.SalesExVAT ELSE 0 END),
[35] = SUM(CASE WHEN sa.FiscalWeek = 35 THEN sa.SalesExVAT ELSE 0 END),
[36] = SUM(CASE WHEN sa.FiscalWeek = 36 THEN sa.SalesExVAT ELSE 0 END),
[37] = SUM(CASE WHEN sa.FiscalWeek = 37 THEN sa.SalesExVAT ELSE 0 END),
[38] = SUM(CASE WHEN sa.FiscalWeek = 38 THEN sa.SalesExVAT ELSE 0 END),
[39] = SUM(CASE WHEN sa.FiscalWeek = 39 THEN sa.SalesExVAT ELSE 0 END),
[40] = SUM(CASE WHEN sa.FiscalWeek = 40 THEN sa.SalesExVAT ELSE 0 END),
[41] = SUM(CASE WHEN sa.FiscalWeek = 41 THEN sa.SalesExVAT ELSE 0 END),
[42] = SUM(CASE WHEN sa.FiscalWeek = 42 THEN sa.SalesExVAT ELSE 0 END),
[43] = SUM(CASE WHEN sa.FiscalWeek = 43 THEN sa.SalesExVAT ELSE 0 END),
[44] = SUM(CASE WHEN sa.FiscalWeek = 44 THEN sa.SalesExVAT ELSE 0 END),
[45] = SUM(CASE WHEN sa.FiscalWeek = 45 THEN sa.SalesExVAT ELSE 0 END),
[46] = SUM(CASE WHEN sa.FiscalWeek = 46 THEN sa.SalesExVAT ELSE 0 END),
[47] = SUM(CASE WHEN sa.FiscalWeek = 47 THEN sa.SalesExVAT ELSE 0 END),
[48] = SUM(CASE WHEN sa.FiscalWeek = 48 THEN sa.SalesExVAT ELSE 0 END),
[49] = SUM(CASE WHEN sa.FiscalWeek = 49 THEN sa.SalesExVAT ELSE 0 END),
[50] = SUM(CASE WHEN sa.FiscalWeek = 50 THEN sa.SalesExVAT ELSE 0 END),
[51] = SUM(CASE WHEN sa.FiscalWeek = 51 THEN sa.SalesExVAT ELSE 0 END),
[52] = SUM(CASE WHEN sa.FiscalWeek = 52 THEN sa.SalesExVAT ELSE 0 END)
FROM
dbo.SalesAggregateWeek sa
WHERE
sa.FiscalYear = 2016;
settings (there is a checkmark in there that needs to be activated; it doesn't work without).mvn install
would, strangely, be helpful. Especially if you have custom configuration for m2e-apt
. Some of that config is interpreted by Java/Compiler
, such as compiler arguments.pom.xml
. That's where maven-compiler-plugin
keeps the list of jars that it scans for annotation processing (you'll find all the jars of your project in there, even though they don't actually contain processors; that is, unless your m2e-apt
is configured as such to only consider a specific list of processors). If the jar containing your processor is not in .factorypath
, it won't work.m2e-apt
will simply ignore your annotation processor; I don't know why. Closing your annotation processor project would be enough in this case (you don't have to delete it from workspace).Edit: Forgot to say that if you do run your annotation processing via Maven (and you're invoking Maven just to process annotations), then maven-compiler-plugin
should be enough. Also, you don't need to run it separately (first .factorypath
then m2e-apt
). You can run it in one shot with mvn compile
; it is supposed to have the exact same effect.
答案 1 :(得分:2)
确保您的Java项目设置(通过右键单击项目> Java compiler > Annotation processors
可访问)确实启用了注释处理,并且设置符合您的预期。
对于Maven项目,m2e应该根据pom.xml内容正确配置这些设置。但是,对于所有Maven插件来说,这并不顺利(有些将支持“开箱即用”,有些则需要特定的插件......)。
答案 2 :(得分:1)
我认为你需要一个触发器来运行Maven目标,所以:
您必须添加有效的maven生命周期操作
由maven install plugin 在本地自动部署的jar示例:
<build>
<!-- ... -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<versionRange>[2.5.0,)</versionRange>
<goals>
<goal>install</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
提示:与Maven Project Builder is invoked every time I change a source file (GWT)有关并作为警告:安装通常包括测试,如果您已将它们包含在正常的maven构建周期中