PackageUtil { public static List<String> getResourceInPackage(String packageName) throws IOException { if (StringUtil.isBlank(packageName)) { return null; } boolean recursive = packageName.endsWith(".*"); String packagePath = getPackagePath(packageName); List<String> resources = CollectionUtil.createArrayList(); String packageDirName = packagePath.replace('.', '/'); URL[] dirs = ClassLoaderUtil.getResources(packageDirName); for (URL url : dirs) { String protocol = url.getProtocol(); if ("file".equals(protocol)) { findResourceInDirPackage(packagePath, URLDecoder.decode(url.getFile(), "UTF-8"), resources); } else if ("jar".equals(protocol)) { findResourceInJarPackage(url, packageName, packageDirName, recursive, resources); } } return resources; }  static List<String> getResourceInPackage(String packageName); static List<String> getClassesInPackage(String packageName); static List<String> getClassesInPackage(String packageName, List<String> included, List<String> excluded); static Package getPackage(Class<?> clazz); static String getPackageNameForObject(Object object); static String getPackageName(Class<?> clazz); static String getPackageName(String javaClassName); static String getResourceNameForObjectClass(Object object); static String getResourceNameForClass(Class<?> clazz); static String getResourceNameForClass(String className); static String getResourceNameForObjectPackage(Object object); static String getResourceNameForPackage(Class<?> clazz); static String getResourceNameForPackage(String className);  }
@Test public void getResourceInPackage() throws IOException { assertNull(PackageUtil.getResourceInPackage(null)); assertNull(PackageUtil.getResourceInPackage("")); assertNull(PackageUtil.getResourceInPackage(" ")); assertTrue(CollectionUtil.isEmpty(PackageUtil.getResourceInPackage("com.baidu.beidou.xxx"))); assertTrue(CollectionUtil.isEmpty(PackageUtil.getResourceInPackage("notexist"))); List<String> utils = PackageUtil.getResourceInPackage("com.baidu.unbiz.common"); assertTrue(CollectionUtil.isNotEmpty(utils)); List<String> subUtils = PackageUtil.getResourceInPackage("com.baidu.unbiz.common.*"); assertTrue(CollectionUtil.isNotEmpty(subUtils)); assertEquals(utils, subUtils); List<String> langs = PackageUtil.getResourceInPackage("org.slf4j"); assertTrue(CollectionUtil.isNotEmpty(langs)); List<String> subLangs = PackageUtil.getResourceInPackage("org.slf4j.*"); assertTrue(CollectionUtil.isNotEmpty(subLangs)); assertEquals(subLangs, langs); }