When I'm working on my web app in Eclipse, I can search all the classes and JAR files with
String cp = System.getProperty("java.class.path");
but when I deploy on Tomcat or Jetty, I get nothing.
I want to find all *.properties files which are located in the webapp (either in the JAR or, if exploded, in folders).
String cp = System.getProperty("java.class.path");
String pathSep = File.pathSeparator;
String[] jarOrDirectories = cp.split(pathSep);
for (String fileName : jarOrDirectories) {
        File file = new File(fileName);
        if (file.isFile()) {
                logger.debug("From jar "+file.getName());
                loadFromJar(file.getPath());
        } else {
                logger.debug("From folder "+file.getName());
                listFolder(file);
        }
}
This way, running the web application in Eclipse gives me all JAR files and all class folders, but not when I deploy the application in Tomcat.
It would be enough if I could just get the path to WEB_INF. From there, it's easy.
If someone needs the answer, I found a very obvious answer.
getServletContext().getRealPath("/WEB-INF")
Then when you receive the real path you can easily search through the folders and JARs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With