How to find out from which jar a class is being loaded in the server for security manager installed classes
Sometimes we cannot alter the classpath of the J2EE server or Web container and we need to find out if the classpath is loading a class from the right jar.
With this JSP example you only have to upload it to your server and load the URL.
In this example we want to locate from where the org.apache.commons.io.IOUtils.class is loaded. Change accordingly.
<%@ page import="java.net.URL"%> <html> <% //choose the class whose jar you want to locate Class c = org.apache.commons.io.IOUtils.class; URL location = c.getResource('/' + c.getName().replace('.', '/') + ".class"); %> <head> <title>Get location package</title> </head> <body bgcolor="#FFFFFF"> <%="Class: "+c.getName()%> <br/> <%="Is located: " + ((c.getProtectionDomain().getCodeSource()==null)?"No source":c.getProtectionDomain().getCodeSource().getLocation()) %> </body> </html>
Upload the JSP and load it with your web browser.
You will see: