BeanShell을 이용해 클래스패스내에서 지정한 클래스 찾기

result) { System.out.println(“——” + search + “—–“); for (int j = 0; j < result.size(); j++) { System.out.println(result.get(j)); } } public List search(String name) { List ret = new ArrayList(); Set set = bcp.getPackagesSet(); Iterator i = set.iterator(); while (i.hasNext()) { search(ret, name, i.next()); } return ret; } private void search(List ret, String name, String packageName) { // パッケージ内のクラス名を一覧する Set set = bcp.getClassesForPackage(packageName); Iterator i = set.iterator(); while (i.hasNext()) { String className = i.next(); // 内部クラスは無視する if (className.indexOf(“$”) >= 0) { continue; } if (className.indexOf(name) != -1) { ret.add(className); } } } public static void main(String[] arg) { SearchClass sc = new SearchClass(); for (int i = 0; i < arg.length; i++) { List ret = sc.search(arg[i]); show(arg[i], ret); } } } [/crayon] ]]>

Related Posts