I'm working on a project based on Java modules. I've a parent project (pom project) that contains other modules, a war module and some jar modules. I want to that a module is a provider, so I've defined a provider class in a module that will be used in an nother module. During the application startup of the webapplication, defined as following:
@WebListener
public class ServletContext implements ServletContextListener ..
I want to get a list of all the services that are provided from a module, so I have used the command:
ServiceLoader<MyClass> services = ServiceLoader.load(MyClass.class);
Unfortunately this instruction doesn't retrieve any service.
So, I've made a new project and tried it to understand if I made some mistakes. In the new project, the ServiceLoader.load, works properly. In this case I'm not using a servlet to test it but I ran it through a Main class. I'm taken these classeds and put in my original project and tried to run them using a Main class, and again the ServiceLoader.load works properly.
It seems that the ServiceLoader.load doesn't work when I invoke it from the web class, ServletContext.
I'm using Java 11, Tomcat 9.0.40.
Is there someone that has already faced this issue?