开发者

Finding the classpath of a web app

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开发者_JS百科 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜