Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Maven JPA integration: processor not found

Parent

Maven JPA integration: processor not found

+1
−0

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:
____pom.xml
____src / main / java:
________com.folder.Project:
____________App.java

There isn't a META-INF directory in the Project hierarchy; it does not get generated when I create Maven projects, but it should not be the issue.

I also some files/ directories to com.folder.Project, resulting in:

com.folder.Project:
____App.java
____archive:
________Annotation.java
____processors:
________AnnotationProcessor.java

This is a new project, and there are not any added files outside of what I have mentioned. These added files even have the same name in my setup; I've set it up like this, purely to troubleshoot + learn how to create annotation processors in java.

Issue: In the terminal, when I run "mvn compile -X" or other similar commands, I get an Error: diagnostic: error: Annotation processor 'com.folder.Project.processors.AnnotationProcessor' not found.

pom.xml:

<artifactid>Project</artifactid>
<version>2024</version>
<packaging>jar</packaging>
<name>Project</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupid>junit</groupid>
        <artifactid>junit</artifactid>
        <version>3.8.1</version>
        <scope>test
    </dependency>
    <dependency>
         <groupid>org.bsc.maven</groupid>
         <artifactid>maven-processor-compiler</artifactid>
         <version>5.0-jdk8</version>
     </dependency>
     <dependency>
         <groupid>org.bsc.maven</groupid>
         <artifactid>maven-processor-plugin</artifactid>
         <version>5.0-jdk8-rc3</version>
     </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupid>org.apache.maven.plugins</groupid>
            <artifactid>maven-compiler-plugin</artifactid>
            <version>3.11.0</version>
        </plugin>
        <plugin>
            <groupid>org.bsc.maven</groupid>
            <artifactid>maven-processor-plugin</artifactid>
            <version>5.0-jdk8-rc3</version>
            <executions>
                <execution>
                    <id>process</id>
                    <goals>
                        <goal>process
                    </goals>
                    <phase>generate-sources</phase>
                        <configuration>
                            <processors>
                                <processor>com.open.Engine.processors.AnnotationProcessor</processor>
                            </processors>
                        </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

The mistake is probably in my pom.
I had to retype 's and 's, so ignore spelling errors related to those; in the XML view on Eclipse, each tag gives a meaningful description (versus, if a tag was spelled incorrectly or misplaced, it might not).

Here are the simple classes I made for testing:

Annotation.java:

// import from java.lang.annotation.Documented;
@Documented
public @interface Annotation { /*does nothing*/ }

AnnotationProcessor.java:

// 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)
    }
}

App.java:

... main( String[] args ) {
    @Annotation int x = 1;
    System.out.println( "finished main" );
}

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


A few notes:

  • diagnostic: error: Annotation processor 'com.folder.Project.processors.AnnotationProcessor' not found; is the 1st error to appear after running mvn compile.

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

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

  • <annotationprocessingpaths>, from an alternative solution, was not a recognized tag in my pom dependency hierarchy (alternative solutions failed too).

  • I have confirmed the spelling is correct in the files, with the correct filenames as well. If you see any spelling errors above, it's probably because I mistyped them into the question-forum text editor.


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.

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

Thank you for your time

  • Tyler Bakeman
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+0
−0

You say this is a personal project. I am sure you were free to chose the technology.

I ask, because Java, annotations and Mvn are good tools for some requirements, but not necessarily the most easy, elegant or efficient ones for everything... it depends.

What exactly is the use of your annotation processors in Java? Is it learning Java annotations (then you are doomed), or building something like... a text editor, a compiler, a game etc.?

Can you avoid annotations altogether? They are again good for certain use cases, but bring a heavy debt: the code is much less readable, as the implementation of the annotation is... somewhere else. They are not good for themselves; at most a necessary evil: avoid if you can.

Same goes for Maven: the version management is fantastic; but if you don't need that, you'll be better off with a more transparent build system, where YOU understand exactly what it does.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Works for me (1 comment)
Works for me
tylerbakeman‭ wrote about 1 month ago

I encounter AP commonly, and it seems important. Though I've only seen it be used for generating new code, and processing old code.

My interest in AP is really niche: I want to be able to use AP for data validation, but different from JUnit test cases (JUnit requires explicit testing). It's possible to make a runtime program that would be able to validate my examples. It would be more elegant to do validation before runtime, and AP seems to fit my needs and interests, but I might not even use any AP.

I know Maven is important, and AP seemed like a good opportunity for me to finally use Maven. I haven't needed to use Maven in my projects; I have never needed to know it; AP seems to require build configuration -- which Maven can provide. Maven is the most common tool used for building professional Java projects. I know Gradle exists (there are a lot of differences); to me, Gradle was more complicated.

Wouldn't it still be very important to learn Maven + AP? Both seem essential.