Good morning. I'm using QDox to parse Java code. What I try to do is verify
that certain classes have an annotation in particularly. The code works
perfectly to run it from Eclipse, however I try to run it with Maven using
a Mojo, and does not work. The file itself is found, but for some reason
does not detect the annotation. That may be failing? Why it works fine from
Eclipse, not from Maven?

Below is the code:

Method to print the class annotations:

*private static boolean printClassAnnotations(JavaClass javaClass) {
 List<JavaAnnotation> annotationList = javaClass.getAnnotations();

 for (JavaAnnotation annotation : annotationList) {
   System.err.println(annotation.getType().getValue());
 }
 return false;
**}*

The main program:

*public static void main(String[] args) {
 JavaProjectBuilder builder = new JavaProjectBuilder();

 builder.addSourceFolder(new File("src/main/java"));

 JavaClass javaClass = builder.getClassByName("org.cyrano.qdox.DemoClass");

 printClassAnnotations(javaClass);
}*

DemoClass is the file with the class that we will analyze.

Here's Mojo:
@Mojo(name = "test", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class MyMojo extends AbstractMojo {

private static boolean printClassAnnotations(JavaClass javaClass) { List<
JavaAnnotation> annotationList = javaClass.getAnnotations(); for (
JavaAnnotation annotation : annotationList) { System.err.println(annotation.
getType().getValue()); } return false; } public void execute() throws
MojoExecutionException { JavaProjectBuilder builder = new JavaProjectBuilder
(); builder.addSourceFolder(new File("src/main/java")); JavaClass javaClass
= builder.getClassByName("org.cyrano.qdox.DemoClass"); printClassAnnotations
(javaClass); } }

if you look good, you will see no difference and it should work fine on
both (Eclipse and Maven), but when I run the Maven Mojo does not work. No
detects the annotation.

Reply via email to