OK, this is going to sound a little weird, but work with me
Suppose I have a Wildfly module extension - deployed in modules/system/layers/base/blahblah and my service all works well.
But now suppose I want a web front end to it. Let's say it is a very simple war - a single servlet, maybe some supporting classes. The servlet and many of its supporting libs/classes (let's say all) are in jars that are in the module extension already. So really, my war just needs to specify a dependency on my module extension (via jboss-deployment-structure.xml).
In fact, to deploy the WAR, my service can do it. I don't need to put the WAR independently in the deployment/ directory; my service extension can add a deploy step during its own initialiation to deploy the war. So even the WAR is inside the service (the web.xml and all is inside modules/system/layers/base/blahblah/main/resources/my.war).
The problem is I believe the WAR will have its own classloader. However, I want the WAR to share the same classloader as the service extension (because, for example, perhaps the service creates some singleton in some third-party lib which I have no control over, but which the WAR needs access to that singleton instance).
Is there anyway to have such a WAR dependency where the WAR can share the classloader of one of its dependencies?
Is there *any* way to do such a thing?
As long as you add a dependency on the extension, in your WAR deployment (it doesn't matter if you use jboss-deployment-structure.xml or do it programatically from within your extension), this should work. The third party singleton will be loaded just once by the classloader which has visibility to that (class) resource.