Search code examples
javadebuggingmavenantannotation-processing

How to step-debug annotation processor during compile?


I have an annotation processor for an annotation of retention policy=SOURCE.

I have not idea how to step-debug it.

  • I have issued print statements, logger info when I run mvn install, compile or package or ant javac, and I see their sysouts in the compile log.

  • However, I have no idea how to step-debug the processor in Eclipse. I mean, how do you step-debug compile-time?


Solution

  • You have to invoke the Java compiler from Eclipse, using a debug configuration (you'll need to create the configuration manually, from the "Debug Configurations..." menu choice.

    The "correct" way to invoke the Java compiler under JDK 1.6 or above is to use the JavaCompiler interface in javax.tools, which you get from the ToolProvider (I include all the links because there's a decent amount of class/package documentation that you should read).

    The "quick-and-dirty" way (that should work, but I make no guarantees) is to invoke com.sun.tools.javac.Main.main(), passing it your normal command-line arguments. To do this, you'll need tools.jar on your classpath (it's found in $JAVA_HOME/lib).