0

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

Gautam
  • 1,030
  • 13
  • 37

1 Answers1

0

ClasspathHelper.forClass(Module.class) returns only Guice's jar, which means your packages would not be scanned.

You need to add more urls to the ConfigurationBuilder.

And you can always scan everything (ClasspathHelper.forClassLoader())...

zapp
  • 1,533
  • 1
  • 14
  • 18