Avaldor
Avaldor

Reputation: 377

How to tell which module does the package belong to?

Given some package foo.bar, how do I find which module does it belong to?

For example, package java.util belongs to module java.base. I can verify it by typing in jdeps -m java.base and by going through the long output. This however assumes my prior knowledge that package java.util belongs to module java.base.

How can I verify which module does the package belong to?

Upvotes: 3

Views: 873

Answers (1)

ZhekaKozlov
ZhekaKozlov

Reputation: 39526

Is this what you want?

Optional<Module> found = ModuleLayer
        .boot()
        .modules()
        .stream()
        .filter(module -> module.getPackages().contains("java.util"))
        .findFirst();

Upvotes: 2

Related Questions