Question

I would like to have classes holding a given annotation listed in a file (ultimately, it will be a .h, but as of now format is not that important).

I know there is a reflections maven plugin that extract metadata during build. But is there any plugin that could use this generated metadata ?

Was it helpful?

Solution

Why don't you write a custom Java Annotation Processor. You just have to implement one single class extending AbstractProcessor. There are several tutorials out there how to write an annotation processor. You just list via @SupportedAnnotationTypes which annotations you are interested in and you get callbacks for each occurrence of these annotations. You can then build up your header file and print it out when processing it done.

If the annotation processor is on your classpath at compile time it will automatically run or you can use the maven-processor-plugin to configure annotation processing explicitly.

OTHER TIPS

Have you thought of doing a simple text based analysis of your .java files using grep, searching for your @Annotation? There is at least one maven plugin that helps with this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top