get web application classes with javaagent?

236 views Asked by At

is there a way to retrieve classes loaded or classloader of the web application?

for example if i use this code :

ClassLoader c=getClass().getClassLoader();
logmsg("c="+c);
URLClassLoader u=(URLClassLoader)c;
URL[] urls=u.getURLs();
for (URL i : urls) {
    logmsg("url: "+i);
}

Im getting librairies used by the agent not the web application

1

There are 1 answers

0
Nicholas On

Take a look at the Reflections package. It uses javassist to provide runtime class meta-data lookup. In order to locate the correct classpath URLs, it provides a helper class ClasspathHelper. ClasspathHelper provides a couple of static methods that return the URLs for WebApps by passing a ServletContext of the target WebApp:

static URL forWebInfClasses(javax.servlet.ServletContext servletContext)
static Set<URL> forWebInfLib(javax.servlet.ServletContext servletContext)