簡體   English   中英

如何在 JPMS 中使用動態創建的層執行“--add-modules”?

[英]How to do "--add-modules" with dynamically created layer in JPMS?

我以這種方式創建 JPMS 層:

Configuration cf = parentLayer.configuration().resolveAndBind(moduleFinder, ModuleFinder.of(), moduleNames);
ModuleLayer layer = parentLayer.defineModulesWithOneLoader(cf, parentClassLoader);

我在添加實現模塊時遇到了問題。 這些實現模塊被 JPMS 忽略,因為這些模塊中的類沒有在任何地方使用(很明顯,API 模塊中的類被使用了)。 因此,JPMS 不會將這些模塊添加到層。

據我了解,如果我談到啟動層上的實現模塊,我可以使用--add-modules jvm 參數。 但是,我找不到任何信息如何強制 JPMS 為動態創建的層加載我的模塊(即使未使用其類)。

誰能說說怎么做?

--add-modules的作用是將給定的模塊添加到根模塊集中。

Configuration#resolveAndBind 允許您使用最后一個參數指定根模塊。 您需要確保要加載的模塊包含在這些根模塊中。

要使用您打算創建的層中所有可能的模塊,您可以使用以下命令:

Set<String> moduleNames = moduleFinder.findAll()
        .stream()
        .map(ModuleReference::descriptor)
        .map(ModuleDescriptor::name)
        .collect(Collectors.toUnmodifiableSet());
Configuration cf = parentLayer.configuration().resolveAndBind(moduleFinder, ModuleFinder.of(), moduleNames)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM