2017-12-05 11 views
2

Java9で必要なモジュールをすべて一覧表示するにはどうすればよいですか?Java9に必要なモジュールをすべてリストしますか?

は、システムモジュールの場合、これは動作します:

ModuleFinder.ofSystem() 
    .findAll() 
    .stream() 
    ... 

をしかし、気圧見ていない私の現在のコードを必要とするモジュールのリストを取得する方法。

この質問は、すべてのモジュールをプログラマチックに問い合せることに関するものです。それはモジュール性の問題を解決することではありません。

答えて

3

あなたはModuleLayerのJavadocで提供されるという名前のモジュールのModuleLayerは記述を見つけると、そのモジュールの依存関係にset of requiresオブジェクトを促進するためのがoneを言わせてもらうために例を利用することをお勧めします。

ModuleFinder finder = ModuleFinder.of(Paths.get("/path/to/module/in/out/production/")); // this is generally a path where I build my modules to 

ModuleLayer parent = ModuleLayer.boot(); 

Configuration cf = parent.configuration() 
         .resolve(finder, ModuleFinder.of(), Set.of("one")); // name of module in module-info 

ClassLoader scl = ClassLoader.getSystemClassLoader(); 
ModuleLayer layer = parent.defineModulesWithManyLoaders(cf, scl); 

layer.modules() 
    .stream() 
    .map(Module::getDescriptor) // get the descriptor of module 
    .map(ModuleDescriptor::requires) // set of requires in the module dependencies 
    .forEach(System.out::println); 
関連する問題