4
当我工作在Eclipse中我的web应用程序,我可以搜索所有的类和JAR文件与找到一个web应用程序的类路径
String cp = System.getProperty("java.class.path");
但是当我在Tomcat或Jetty部署,我得到没有。
我想找到位于webapp中的所有*.properties
文件(无论是在JAR中,还是在分解文件夹中)。
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);
}
}
这种方式,运行在Eclipse Web应用程序给了我所有的JAR文件和所有类文件夹,而不是当我部署在Tomcat中的应用。
如果我能找到路径WEB_INF
就足够了。从那里,很容易。
java.class.path属性可能不是你想要的。 Webapps具有影响可见性的自定义类加载器层次结构。有关更多信息,请参阅http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html。你能提供一个代码示例来演示你正在尝试做什么吗? – g051051