javaweldweld-se

Hooking into WELD-SE classpath scanner


I've been looking for documentation on WELD-SE's classpath scanner API, but haven't been able to find any. I'm trying to discover POJOs with custom annotations in the spirit of the Servlet, WebSocket and JAX-RS APIs. Is there any way to do this with WELD?

I realize that there are already libraries that do classpath scanning, such as Scannotation, FastClasspathScanner, Corn-CPS, etc., but I'm trying to keep this project lean and don't mind tight integration with WELD.


Solution

  • Weld doesn't have any such API. The scanner Weld uses is not "general-enough" for this. It is rather CDI-specific as it focuses on discovering bean archives.

    If the POJOs you are looking for are in fact CDI beans, you could simply write a CDI extension and observe ProcessAnnotatedType<?> phase which will notify you of all AnnotatedTypes CDI picks up. This can be further narrowed down using @WithAnnotations to only select AT with given annotations.

    In certain environments, Weld also allows to work with Jandex which is something you could perhaps use as a different tool.