BeanUtil { public static Set<Class<?>> getClasses(final String pk) throws UtilException { boolean recursive = false; String[] packArr = {}; String pack = pk; if (pack.lastIndexOf(SUB_PACKAGE_SCREEN_SUFFIX) != -1) { packArr = pack.split(SUB_PACKAGE_SCREEN_SUFFIX_RE); if (packArr.length > 1) { pack = packArr[0]; for (int i = 0; i < packArr.length; i++) { packArr[i] = packArr[i].replace(SUB_PACKAGE_SCREEN_SUFFIX.substring(1), ""); } } else { pack = pack.replace(SUB_PACKAGE_SCREEN_SUFFIX, ""); } recursive = true; } Set<Class<?>> classes = new LinkedHashSet<Class<?>>(); String packageName = pack; String packageDirName = packageName.replace('.', '/'); Enumeration<URL> dirs; try { dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName); while (dirs.hasMoreElements()) { URL url = dirs.nextElement(); String protocol = url.getProtocol(); if ("file".equals(protocol)) { logger.debug("-------------- scan type file ----------------"); String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); findAndAddClassesInPackageByFile(packageName, packArr, filePath, recursive, classes); } else if ("jar".equals(protocol)) { findAndAddClassesInPackageByJarFile(packageName, packArr, url, packageDirName, recursive, classes); } } } catch (IOException e) { throw new UtilException(ErrorCodeDef.READ_FILE_ERROR_10028); } return classes; }  static boolean isAbstract(final Method method); static String[] getMethodParamNames(final Class<?> clazz, final String method, final Class<?>... paramTypes); static String[] getMethodParamNames(final Method method); static String getMethodSignature(final Method method); static Set<Class<?>> getClasses(final String pk); static String toUnderlineName(final String s); static String toCamelCase(final String str); static String camelStr2underLine(final String camelStr); static String toCapitalizeCamelCase(final String str); static boolean isSimpleValueType(final Class<?> clazz); static boolean isSimpleProperty(final Class<?> clazz);  }
@Test public void getClasses() { Set<Class<?>> classes = BeanUtil.getClasses("com.hbasesoft.framework.common.utils.bean"); Assert.notEmpty(classes, ErrorCodeDef.SYSTEM_ERROR_10001); System.out.println("找到了com.hbasesoft.framework.common.utils.bean下所有的类"); }