I want to inspect some classes in my .war file right after I have deployed it. But I don't know how to achieve this (most likely due to my lack of JavaEE understanding).
I tried something like below using ClassPath from google's Guava library. It finds all sorts of classes when I pass “com” as an argument. However when passing “com.mypackage” nothing is found.
Any help is appreciated.
@Startup
@Singleton
public class Inspector {
@PostConstruct
public void inspect() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
//ClassLoader classLoader = ClassLoader.getSystemClassLoader(); // doesn't make any difference
ClassLoader classLoader = this.getClass().getClassLoader(); // // doesn't make any difference
try {
for (final ClassPath.ClassInfo info : ClassPath.from(classLoader).getTopLevelClassesRecursive("com.mypackage")) {
System.out.println(info.getName());
}
} catch (IOException e) {
e.printStackTrace();
}
}
….
..
Aucun commentaire:
Enregistrer un commentaire