Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define myAnnotationProcessor programmatically in source code?

I'm just new to annotations. I've created a sample annotationProcessor to handle my annotations and currently using command line script "-processor defaultproject.annotations.DefaultProcessor " to use it.

is there any way to set this processor from inside the code?

thanks a lot Moein

like image 683
Moein Avatar asked Feb 15 '26 00:02

Moein


1 Answers

The Processor interface says this about the discovery process:

The tool uses a discovery process to find annotation processors and decide whether or not they should be run. By configuring the tool, the set of potential processors can be controlled. For example, for a JavaCompiler the list of candidate processors to run can be set directly or controlled by a search path used for a service-style lookup. Other tool implementations may have different configuration mechanisms, such as command line options; for details, refer to the particular tool's documentation.

Your best bet for defining the processor in your classpath is to provide a META-INF/services/javax.annotation.processing.Processor file containing the text defaultproject.annotations.DefaultProcessor.

(Assuming your tool chain supports this mechanism. This is ultimately compiler/tool/IDE dependent.)

like image 175
McDowell Avatar answered Feb 17 '26 13:02

McDowell