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
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
Post
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.
0 comment threads