On 16/11/2020 09:17, Alex Orlov wrote:
Hello Alan,
Thank you for such detailed answer. I read it with attention, but still don’t know how to solve my situation.
Maybe may question didn’t provide all details, so here they are.
I want to create the following layer structure:
+++++++++++
+ Boot Layer +
+++++++++++
       |
       +++++++++++++++++
       + Web Server Layer +
       +++++++++++++++++
                         |
                         ++++++++++++++++++++
                         + Web Application Layer +
                         ++++++++++++++++++++
So, we have always one boot layer (it’s clear), one web server layer, and multiple web application layers. At the same time all web application layers have one parent — web server layer. Boot layer doesn’t know and mustn’t know about any child layer modules!!!! So it is impossible to add all modules to boot layer! In web server layer I have servlet container (Jetty) and rest implementation (Jersey). When I create web server layer Configuration cf = parentLayer.configuration().resolveAndBind(moduleFinder, ModuleFinder.of(), moduleNames); ModuleLayer layer = parentLayer.defineModulesWithOneLoader(cf, parentClassLoader); I add to it all modules of jetty, jersey and their dependencies. At the same time jetty knows nothing about jersey. When web server layer is created one of its modules starts Jetty. So, when does jersey start? It starts only when web application layer is created with .war file that has web.xml with jersey servlet. For example:
<servlet>
        <servlet-name>JerseyServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
</servlet>
So, in such configuration, when web server layer is created no one can know if jersey will be used. What what does JPMS do? It ignores all jersey modules including all its dependencies (including API). So, the question.
How to ask JPMS not to ignore modules that it must add to layer?

Thanks for the diagram, and names, of the module layers.

If I read your mail correctly then you are saying that the Jersey module is observable when you create the configuration for "Web Server Layer". It is not resolved because it's not in the set of root modules that you specify to resolveAndBind. It is also not required by any of the modules that end up in the configuration. This should not be a surprise. If the intention for "Web Server Layer" to contain Jersey and other modules that web applications may need then you will need to add them to the set of root modules ("moduleNames" in your code fragment. If the modules are completely unrelated then you might want to scan them so that "moduleNames" has the names of the modules that export an API.

Does the .war file containing "JerseyServlet" have a module-info.class? I'm curious if it declares "requires Jersey" as I would expect that the resolve or resolveAndBind for the web application will fail if it requires Jersey and it is not observable or is not in the parent layer.

-Alan

Reply via email to