Here you can find the source of getClasses(ClassLoader cl, String pack)
public static List<Class> getClasses(ClassLoader cl, String pack) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.List; public class Main { public static List<Class> getClasses(ClassLoader cl, String pack) throws IOException { String dottedPackage = pack.replaceAll("[/]", "."); List<Class> classes = new ArrayList<Class>(); URL upackage = cl.getResource(pack); DataInputStream dis = new DataInputStream((InputStream) upackage.getContent()); String line = null;//from ww w. ja va 2 s. c o m while ((line = dis.readLine()) != null) { if (line.endsWith(".class")) { try { classes.add(Class.forName(dottedPackage + "." + line.substring(0, line.lastIndexOf('.')))); } catch (Exception e) { } } } return classes; } public static String substring(String str, int offset, int length) { if ((offset + length) > str.length()) { length = str.length() - offset; } return str.substring(offset, offset + length); } }