ClasspathScanner { public List<Class<?>> getClassesWithAnnotation(final Class<? extends Annotation> desiredAnnotation, final ClassLoader classLoader, final String[] cpElements) { final List<Class<?>> classList = new ArrayList<Class<?>>(); final List<String> classNameList = new ArrayList<String>(); for (final String cpElement : cpElements) { final File f = new File(cpElement); if (f.exists() && f.isDirectory()) { final List<File> files = getAllFiles(f, "class"); for (final File classFile : files) { classNameList.add(convertFileToClass(classFile, f)); } } else { JarFile jarFile = null; try { jarFile = new JarFile(f); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry nextElement = entries.nextElement(); if (!nextElement.isDirectory()) { final String name = nextElement.getName(); if (name.endsWith(".class")) { final String classname = name.replace(File.separatorChar, '.'); classNameList.add(classname.substring(0, classname.length() - 6)); } } } } catch (final IOException e) { } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { } } } } } for (final String className : classNameList) { try { if (!className.contains("$")) { final Class<?> clazz = classLoader.loadClass(className); if (clazz.isAnnotationPresent(desiredAnnotation)) { classList.add(clazz); } } } catch (final NoClassDefFoundError e) { } catch (final ClassNotFoundException e) { } } return classList; }  List<Class<?>> getClassesWithAnnotation(final Class<? extends Annotation> desiredAnnotation,
                                                   final ClassLoader classLoader, final String[] cpElements); List<Class<?>> getClassesWithAnnotation(final Class<? extends Annotation> desiredAnnotation,
                                                   final ClassLoader classLoader);  }
@Test public void testClasspathResolution() { System.out.println(System.getProperty("java.class.path")); final ClasspathScanner cpScanner = new ClasspathScanner(); final List<Class<?>> classesWithAnnotation = cpScanner.getClassesWithAnnotation( SubSteps.StepImplementations.class, Thread.currentThread().getContextClassLoader()); Assert.assertNotNull(classesWithAnnotation); Assert.assertThat(classesWithAnnotation.contains(MockStepImplementations.class), is(true)); }