問題描述
Maven 編譯器插件的文檔中提到了以下內容:
注解處理器:
要運行的注釋處理器的名稱.僅適用于 JDK 1.6+ 如果不是設置,則應用默認注釋處理器發現過程.
Names of annotation processors to run. Only applies to JDK 1.6+ If not set, the default annotation processors discovery process applies.
這里的默認注釋處理器發現過程是什么?除了這個配置標簽,還有其他方法可以設置注解處理器嗎?
What is the default annotation processors discovery process here? Is there any other way to set up annotation processors than this configuration tag?
我發現入門注釋處理工具 (apt) 文檔提到了一個默認發現過程,但它適用于 工廠類 而不是處理器,不幸的是它使用 tools.jar來自 JDK 的
和 com.sun
包.這是默認的注釋處理器發現過程嗎?
I've found that the Getting Started with the Annotation Processing Tool (apt) documentation mentions a default discovery procedure, but it works with factory classes not processors and unfortunately it uses the tools.jar
and com.sun
packages from the JDK. Is this the default annotation processors discovery process?
推薦答案
讓編譯器可以使用注解處理器的默認方法是在 META-INF/services/javax.annotation 的文件中注冊它.processing.Processor
.該文件可以包含許多處理器:每個處理器都在其自己的行上是完全限定的類名,最后有一個換行符.如果未指定任何處理器,編譯器將默認使用以這種方式找到的處理器.
The default way to make an annotation processor available to the compiler is to register it in a file in META-INF/services/javax.annotation.processing.Processor
. The file can contain a number of processors: each the fully-qualified class name on its own line, with a newline at the end. The compiler will default to using processors found in this way if none are specified.
這篇關于什么是默認注釋處理器發現過程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!