I am using the http://reflections.googlecode.com/ utility
This is a method I am trying to execute
// Only top level modules should be added to this list
protected Set<Class<? extends Module>> discoverModulesOnClassPath() {
// Scan classpath to identify modules
Predicate<String> filter = new FilterBuilder().includePackage("org.appops.server.core.bindings") ;
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner()).setUrls(asList(ClasspathHelper.forClass(Module.class))));
Set<Class<? extends Module>> guiceModules = reflections.getSubTypesOf(Module.class);
return guiceModules;
}
And this is my test
@Test
public void testDiscoverModulesOnClassPath() {
AppOpsCoreServletConfig config = new AppOpsCoreServletConfig() ;
Set<Class<? extends Module>> modules = config.discoverModulesOnClassPath() ;
for ( Class m : modules){
System.out.println(m.getSimpleName());
}
}
I have 3 custom module in the specific package ( have cross checked the path ) but it prints this list of classes
ProviderMethodsModule
AbstractModule
RootModule
PrivateModule