This content has been marked as final. Show 3 replies
Ok. The root problem was that to create my processor I followed a tutorial that, I'm guessing, is out of date - it used explicit references to com.sun.* packages rather than the javax.annotations.* packages. Because the AnnotationProcessor interface in the com.sun.* packages are not even close to being the same as the javax stuff, the whole thing was broken in that apt didn't know how to locate the factory class, and if I explicitly gave it the processor class it threw it out because it didn't implement the Processor interface. Basically my whole problem boiled down to confusion regarding which packages I should have been using.
The fog cleared once I realized that Java 6's javac handles annotations without requiring apt - provided you use the right classes to start with. So I rewrote my processor using the javax patterns and got it to compile, and built a jar that I could use against test sources with my annotations in place. I still had a problem in that the discovery mechanism wasn't finding my processor when compiling the test sources; that particular wisp of fog cleared once I read that you need a META-INF/services/javax.annotation.processing.Processor text file in the classpath. With that in place, everything started working.
My processor now uses my annotations and can generate output Java sources (using Velocity templates for the sources; the Processor just builds the contexts from the annotated Class and Method declarations) that get compiled alongside the annotated sources without me having to take any special actions. Sweet. I used to do this junk using reflection, but using annotations gives me better control (I can limit the methods I'm concerned with by annotating just those) and I don't need a three step compile-generate-compile process.