Annotation processors and the --processor-module-path

Eirik Bjørsnøs eirbjo at gmail.com
Mon Nov 21 10:39:58 UTC 2016


> Currently, AFAIK, the processors on module path need to be registered in
> the ServiceLoader. For --processor-module-path, "-processor" can be used to
> select processors out of those registered in the ServiceLoader. If
> --processor-module-path is used and there is no "-processor", all
> processors registered in ServiceLoader are considered, AFAIK. Please note
> that (as before) the processors are only run if their
> SupportedAnnotationTypes match, etc.
>
> I tried a simple example as well, and with the proper "provides" the
> annotation processor was run. Is there a testcase we could try?
>


Jan,

I've updated the testcase on Github:

https://github.com/eirbjo/java-xml-bind-processor

How to reproduce:

$ mvn clean install
$ cd example-module

Now (since Maven doesn't know about --processor-module-path):

$ javac -d target/classes --processor-module-path
 ~/.m2/repository/com/example/annotation-processor/1.0-SNAPSHOT/annotation-processor-1.0-SNAPSHOT.jar
-sourcepath src/main/java src/main/java/com/example/module/SomeClass.java

No output - the processor is not applied.

However:

$ javac -d target/classes -classpath
~/.m2/repository/com/example/annotation-processor/1.0-SNAPSHOT/annotation-processor-1.0-SNAPSHOT.jar
-sourcepath src/main/java src/main/java/com/example/module/SomeClass.java
Running ProcessorUsingJavaXmlBind.process
 java.xml? true
 java.xml.bind? false


The processor was now applied.

Note that the test case now has provides in module-info.java _and_  the
ServiceLoader file in META-INF/services. I tried removing the services
file, no change.

Eirik.


More information about the jigsaw-dev mailing list