I am working on a maven projet and i added to my pom.xml file the guava dependency. I want to get all class of a given package and it will be better if i can get the list of package too. So i tried with this :
public void getClassOfPackage() {
final ClassLoader loader = Thread.currentThread()
.getContextClassLoader();
try {
for (final ClassPath.ClassInfo info : ClassPath.from(loader)
.getTopLevelClasses()) {
if (info.getName().startsWith("org.mypackage")) {
final Class<?> clazz = info.load();
System.out.println(clazz.getName());
} else {
System.out.println(loader.getClass().getName());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new ClassOfPackage().getClassOfPackage();
}
but it gives me that :
sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$AppClassLoader...
Aucun commentaire:
Enregistrer un commentaire