Given a package, is it possible to find all the classes in it?
For instance, how do you find out what classes are contained within java.lang
?
Thanks
Given a package, is it possible to find all the classes in it?
For instance, how do you find out what classes are contained within java.lang
?
Thanks
This should get you started (look at the console output, it will make sense):
import com.google.common.collect.Multimap;
import org.reflections.Reflections;
import java.util.Map;
public class PackageWalker {
public PackageWalker() {}
public void walk() {
Reflections reflections = new Reflections("org.reflections");
for (String mmapName : reflections.getStore().getStoreMap().keySet()) {
System.out.println("KEY["+mmapName+"]");
Multimap<String,String> mmap = reflections.getStore().getStoreMap().get(mmapName);
for (Map.Entry<String,String> entry: mmap.entries()) {
System.out.println(" PAIR[ "+entry.getKey()+"="+entry.getValue()+" ]");
}
}
}
public static void main(String[] args) {
new PackageWalker().walk();
}
}
Following jars and their dependencies are required (using Ivy format):
<dependency org="org.reflections" name="reflections" rev="0.9.8"/>
Here is my project folder: http://www.filedropper.com/laboratorytar
You just need to make sure Ivy is installed with ant (essentially put ivy.jar into your ANT_HOME/lib (or ~/.ant/lib/ on *nix) and it will just work).