How to configure Java Annotation Processor(s) in Eclipse?
Asked Answered
P

3

12

I have successfully run annotation processor for CLASS level retention annotations via command prompt compiling using Java 8.

However, when I tried to configure the annotation processor in eclipse and tried to run it with "-proc:only" option, it didn't get effective.

I have included the Jar file containing the custom annotation processor class file into the Project Properties -> Annotation Processing -> Factory Path. I have also provided the -proc:only option in Project Properties -> Annotation Processing -> Processor Options, still the annotation processor isn't getting called when a class containing my annotation is executed.

Please help me identifying the required setting or mistake or additional step for running the annotation processor via eclipse.

Prase answered 14/4, 2017 at 3:43 Comment(0)
M
20

I was finally able to enable my own annotation processor by adding my jar file.

  1. Right click on the project and select Properties.
  2. Open Java Compiler -> Annotation Processing. Check "Enable annotation processing".
  3. Open Java Compiler -> Annotation Processing -> Factory Path. Check "Enable project specific settings". Add your JAR file to the list.
  4. Clean and build the project.

And it finally worked.

Mullock answered 21/6, 2017 at 11:23 Comment(2)
Thanks for this, was just what I needed!Macrogamete
Thank you so much, I was going crazy about this! Needed to add mapstruct-annotation-processor to Factory Path to make it work with EclipseBionomics
R
5

It is very much straightforward provided that whatever APT plug in you are trying to use is correctly configured.

Follow the steps mentioned in above post and the reference image to visualize it. Image showing QueryDsl APT configuration for maven project.

enter image description here

Regale answered 15/12, 2017 at 12:9 Comment(0)
S
0

While compiling via command prompt or terminal, you can see all the logs in same screen after the compilation command. In eclipse, these logs can be seen at

Window->show view->General->Error Log

If you want the IDE(Eclipse) to point out the warning, error or other diagnostic message exactly at the particular element in the code editor, we have to call the printMessage method of javax.annotation.processing.Messager with 3 arguments as shown below.

messager.printMessage(Kind.ERROR, "Error Message", element);

Shela answered 30/1, 2019 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.