Monday, March 14, 2022

[SOLVED] How to specify an AbstractProcessor on the apt/javac command line?

Issue

I have a class that extends rel="nofollow">javax.annotation.processing.AbstractProcessor, which I'd like to run over some .java files with apt.

How do I specify the class name on the apt command-line (or in an ant apt task)? The command-line options I see, such as -factory expect an AnnotationProcessorFactory, not an AbstractProcessor.


Solution

I use javac 1.6.0_20.

The relevant options for my compiler are

  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...]Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files

I suspect you are using javac 1.5.*. That JDK does not work with AbstractProcessor (which was introduced in 1.6). The solution is to upgrade your JDK.



Answered By - emory
Answer Checked By - Marie Seifert (WPSolving Admin)