Get a list of resources from classpath directory

前端 未结 14 926
予麋鹿
予麋鹿 2020-11-22 05:20

I am looking for a way to get a list of all resource names from a given classpath directory, something like a method List getResourceNames (String direct

14条回答
  •  太阳男子
    2020-11-22 06:08

    The most robust mechanism for listing all resources in the classpath is currently to use this pattern with ClassGraph, because it handles the widest possible array of classpath specification mechanisms, including the new JPMS module system. (I am the author of ClassGraph.)

    List resourceNames;
    try (ScanResult scanResult = new ClassGraph().whitelistPaths("x/y/z").scan()) {
        resourceNames = scanResult.getAllResources().getNames();
    }
    

提交回复
热议问题