简体   繁体   English

在Eclipse 4.6 Neon中使用注释处理器

[英]Working with annotation processors in Eclipse 4.6 Neon

I am maintaining a Java 7 web project that uses multiline annotation to store certain constants. 我正在维护一个Java 7 Web项目,该项目使用多行注释来存储某些常量。

I could configure Eclipse fine when I was using Mars, so I could launch Tomcat with that application deployed and it worked like a charm... 我可以在使用Mars时配置Eclipse,所以我可以在部署该应用程序的情况下启动Tomcat,它就像魅力一样......

Until I upgraded! 直到我升级! Now no annotation processing is done despite the configuration . 现在,尽管配置完成,仍未完成注释处理。

I have found that this problem is due to a feature of Eclipse 4.6, as documented here 我发现这个问题是由Eclipse 4.6的一个特性引起的,如此处所述

Java 6 annotation processors are supported in the batch compiler and in the IDE. 批处理编译器和IDE中支持Java 6批注处理器。 By design, Java 6 processors are only executed during a build, not while editing. 按照设计,Java 6处理器仅在构建期间执行,而不是在编辑时执行。 (bug 188558) (bug 188558)

The linked bug says, in brief, that annotation processing has been removed from Eclipse's incremental compilation (perhaps the Build automatically ???) for legitimate reasons. 简而言之,链接的错误说明注释处理已经从Eclipse的渐进式编译中删除(可能是Build automatically ???),这是出于正当理由。 And in fact when I compile my project in CI server using Ant, annotations get processed as usual. 事实上,当我使用Ant在CI服务器中编译项目时,注释会照常处理。

But I can't run my project anymore in Eclipse. 但我不能再在Eclipse中运行我的项目了。 It fully depends on the correct processing of the Multiline annotation. 它完全取决于Multiline注释的正确处理。

So far, I have tried to disable the Build Automatically flag and manually build the project. 到目前为止,我已尝试禁用Build Automatically标志并手动构建项目。 No result . 没有结果

I also tried to go to Java Compiler -> Annotation processing -> Factory Path , select the multiline-string jar, go to Advanced properties and uncheck Run this container's processors in batch mode , despite the checkbox is counterintuitive (I mean, it should be named "Run in incremental mode" and unchecked by default, according to the above mentioned bug) 我还尝试Java Compiler -> Annotation processing -> Factory Path ,选择multiline-string jar,转到Advanced属性并取消选中Run this container's processors in batch mode ,尽管复选框是违反直觉的(我的意思是,它应该是名为“以增量模式运行”并默认未选中,根据上述错误)

The application is a web application, so on every attempt I try to deploy it to local Tomcat. 该应用程序是一个Web应用程序,因此每次尝试将其部署到本地Tomcat。

What do you think I can do about it? 你觉得我能做些什么?

A couple of suggestions: 一些建议:

  1. The multiline annotation you are using only supports up to Java version 1.6. 您使用的多行注释仅支持Java版本1.6。 (For instance, MultilineProcessor specifies @SupportedSourceVersion(SourceVersion.RELEASE_6) , and the recommended pom settings specify source and target values of 1.6 .) If your package is building with a JDK Compliance Level greater than 1.6, this is probably why the annotations are being ignored. (例如, MultilineProcessor指定@SupportedSourceVersion(SourceVersion.RELEASE_6) ,推荐的pom设置指定1.6 sourcetarget 。)如果您的包正在构建, JDK合规性级别大于1.6,这可能就是注释的原因忽略。
  2. Instead of using that annotation, you could just hard-code the multiline strings to your string variables. 您可以将多行字符串硬编码为字符串变量,而不是使用该注释。 It would make your code less readable, but builds will be faster. 它会降低您的代码的可读性,但构建速度会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM