java - How to get all jar from classpath of Tomcat application? -
i need write new module, able application's jar in runtime.
i try getting inforimation classloader.getsystemclassloader()
, catalina.bat
in tomcat override variable of classpath.
so, next idea recursively iterate through target folders , lib folder. in module wrote :
public class mainservlet extends httpservlet { @override protected void service(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception { file currentdir = new file(getservletcontext().getrealpath("/")); // current directory system.out.println("cur dir: " + currentdir); displaydirectorycontents(currentdir); } }
i got result:
cur dir: c:\java\apache-tomcat-7.0.56\webapps\jar
this path war, added application. need path application itself.
so, have idea?
java ee applications have customized classloader
hierarchy.
public class mainservlet extends httpservlet { @override protected void service(httpservletrequest req, httpservletresponse resp) { classloader effectiveclassloader = getclass().getclassloader(); url[] classpath = ((urlclassloader) effectiveclassloader).geturls(); ... } }
Comments
Post a Comment