1

让我们考虑以下情况。我有两层:

  • 引导层
  • 我的自定义层

引导层是 mycustom 层的父级。除了我有三个模块:

  • 模组.a
  • 模组.b
  • 模组

在 mod.a 的模块信息中,我有

module mod.a {
   requires mod.b;
}

在 mod.c 的模块信息中,我有

module mod.c {
   requires mod.b;
}

在引导层我有 mod.a 和 mod.b。在 mycustom 层中,我有 mod.b 和 mod.c(出于某些原因,我希望在该层中有 mod.b)。但是,我得到以下异常:

java.lang.module.ResolutionException: mod.c 读取多个名为 mod.b 的模块。

是否可以在 mycustom 层中的模块的引导层中“隐藏”mod.b?如果是,那么如何?

这是我创建自定义层的方式:

ModuleFinder finder = ModuleFinder.of(...);
ModuleLayer parent = ModuleLayer.boot();
Configuration cf = parent.configuration().resolve(finder, ModuleFinder.of(), Set.of("mod.b, mod.c"));
ClassLoader scl = ClassLoader.getSystemClassLoader();
ModuleLayer myCustomLayer = parent.defineModulesWithOneLoader(cf, scl);
4

0 回答 0