PluginsViaAnnotations { public static List<Class<?>> findAnnotatedClasses(String packageName, Class<? extends Annotation> annotationClass) throws Exception { List<Class<?>> ret = new ArrayList<>(); String[] clazzNames = ClassesInPackage.getPackageContent(packageName); for (String clazzName : clazzNames) { if (!clazzName.endsWith(".class")) { continue; } clazzName = clazzName.replace('/', '.').replace(".class", ""); Class<?> c = null; try { c = Class.forName(clazzName); } catch (ClassNotFoundException ex) { System.err.println("Weird: class " + clazzName + " reported in package but gave CNFE: " + ex); continue; } if (c.isAnnotationPresent(annotationClass) && !ret.contains(c)) ret.add(c); } return ret; }  static List<Class<?>> findAnnotatedClasses(String packageName,
		Class<? extends Annotation> annotationClass); static List<Class<?>> findClassesWithAnnotatedMethods(String packageName, 
			Class<? extends Annotation> methodAnnotationClass);  }
@Test @MyTestAnnotation void testFindAnnotatedClasses() throws Exception { List<Class<?>> ret = PluginsViaAnnotations.findAnnotatedClasses("reflection", MyTestAnnotation.class); assertEquals(1, ret.size()); assertSame(PluginsViaAnnotationsTest.class, ret.get(0)); }