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

PavelTurk pavelturk2000 at gmail.com
Sun Aug 25 07:39:15 UTC 2024


Thank you very much for your reply.

Yes, I also thought about getting all classes and iterating them, but I thought that there were different ways.

And a last question. Why there is no API that provides all existing layers. For example ModuleLayer:getLayers() to return all
layers and what you think about adding this API?

Best regards, Pavel

On 8/25/24 10:29, Alan Bateman wrote:
>
>
> 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