How to get JPMS layers from external java application using agent?

Alan Bateman alan.bateman at oracle.com
Sun Aug 25 07:29:44 UTC 2024



On 24/08/2024 11:51, PavelTurk wrote:
> Hello all.
>
> Let's consider there are two java applications (in two different 
> processes). Application A is mine and I can do whatever I want with it.
> Application B is the application I can't (or I don't want to) modify.
>
> Now in Application A I need to get information about Application B 
> JPMS layers, JPMS modules etc. As I understand I can do
> it via java agent. But I can't find information how I can get all JPMS 
> layers of the Application B in this agent.
>
> Could anyone say how to do it, if it is possible. Or maybe there are 
> different ways to do it.

There aren't any APIs to enumerate "all module layers". However, if B is 
deployed with a Java agent that is under A's control then code in the 
agent can use Instrumentation::getAllLoadedClasses and use that to 
reconstruct the directed graph of modules layers (see Class::getModule 
and Module::getLayer). It would of course require an out of band means 
to communicate a representation of that graph to A but that shouldn't be 
too hard.

-Alan


More information about the jigsaw-dev mailing list