I need to write a new module that can get all jar applications at runtime.
I'm trying to do this with getting information using Classloader.getSystemClassloader(), but catalina.batin Tomcat overrides the classpath variable.
So, the next idea was to recursively iterate over all the target folders and look for the lib folder . In my module, I wrote:
public class MainServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
File currentDir = new File(getServletContext().getRealPath("/"));
System.out.println("Cur dir: " + currentDir);
displayDirectoryContents(currentDir);
}
}
I got this result:
Cur dir: C: \ Java \ apache-tomcat-7.0.56 \ webapps \ jar
This is the path to my war that I added to the app. But I need a path to the application itself.
So do you have any ideas?