2017-12-05 12 views
2

Java9에서 필요한 모든 모듈을 나열하려면 어떻게합니까?Java9에서 필요한 모든 모듈을 나열 하시겠습니까?

시스템 모듈의 경우,이 작품 :

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

을하지만, 기압 표시되지 내 현재 코드 를 필요로하는 모듈의 목록을 얻는 방법.

이 질문은 프로그래밍 방식으로 모든 모듈을 쿼리하는 것에 관한 것입니다. 모듈성 문제를 해결하는 것이 아닙니다.

답변

3

당신은라는 이름의 모듈의 ModuleLayer이의이 설명을 찾아 그 모듈 종속성에서 set of requires 객체를 촉진하기 위해 one을 가정 해 봅시다 얻을 수 ModuleLayer의 자바 독에 규정 된 예제의 사용을 할 수 있습니다.

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);