Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Personal Project:
I am new to Maven and have spent a few weeks troubleshooting pom errors with chatGPT. Tutorials are hard to come by online, because annotation-processing in Java is more complicated than the sources I've found. Issue in summary: my annotation processor "cannot be found" but everything \~looks okay. I need help spotting the issue in my Pom; Thank you in advance!

Background: In Eclipse IDE, I created a new Maven project with the quickstart architype resulting in a project with this structure:
Project \>
src / main / java \>
com.folder.Project \>
\-- which is pretty simple. There isn't a META-INF directory in the Project hierarchy, which \~shouldn't be an issue.
\*This is a new project, so there isn't any added code outside of the files I mention below, keeping things simple:

in com.folder.Project \>
archive \>
processors \>
\-- which are the actual file names.

In the terminal, when I run "mvn compile" or other commands that would use the pom, I get an Error:
diagnostic: error: Annotation processor 'com.folder.Project.processors.AnnotationProcessor' not found.

file data below: ( 'Sorry' to smart-phone users of stackoverflow, for the formatting )




\-- which to me, looks fine (just the 1st plugin looks unnecessary). If there is a mistake lmk.

More details:
I'm trying to build annotation processors in Java; I think it has potential for lots of future projects. I understand it's a little niche, but also think it is probably important to know / be able to use effectively.

Here are the simple classes I made for testing:
package com.folder.Project.archive;
// import from java.lang.annotation.Documented;
public @interface Annotation { }
package com.folder.Project.processors;
// imports from javax, and java.util.Set;
@SupportedAnnotationTypes( "com.folder.Project.archive.Annotation" ) // I'm not sure if this matches
public class AnnotationProcessor extends AbstractProcessor {
    @Override public boolean process ( ... ) // Set and RoundElement inputs
        processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, "Error" );
        return false; // so it should fail every time (which lets me know if it works)
import com.folder.Project.archive.Annotation;
... main( String[] args ) {
    @Annotation int x = 1;
    System.out.println( "finished" );

The code is written so I can verify an annotation processor is executed at all.

What steps should I take to get everything running normally, for annotation processing? What errors have I made?

I have confirmed the spelling is correct in the files, with the correct filenames as well. If you see any spelling errors above, you can probably ignore them.

Thank you!
I'm sure it's just my inexperience.

What I have tried:

In the terminal, when I run "mvn compile" or other commands that would use the pom, I get an Error:
diagnostic: error: Annotation processor 'com.folder.Project.processors.AnnotationProcessor' not found.

"mvn clean compile -X" doesn't elaborate on the error: Build Fail / could Not Execute / could not achieve goal.

diagnostic: error: Annotation processor 'com.folder.Project.processors.AnnotationProcessor' not found. is the 1st error ( there isn't an error before this one ).

I run "Build Project", "Build All", and "Run" after every significant change to pom.xml.

pom.xml tags (\<tag\> ... \) all show descriptions normally-- which could be useful to know.

\<annotationprocessingpaths\> didn't work with my dependencies, but maybe it's just missing that, or maybe this pom.xml doesn't have an issue.
Updated 15-Mar-24 17:25pm

1 solution

The beauty of annotation processing is that it doesn't require you to explicitly pick a type in the @SupportedAnnotationTypes. Change that line to @SupportedAnnotationTypes("*") and this should pick up any annotations that you have in the project.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900