Java Tomcat webapp的工作目录
我有一个部署在ApacheTomcat6服务器上的Java web应用程序。该应用程序包含一个添加到类路径的Java Tomcat webapp的工作目录,java,tomcat,Java,Tomcat,我有一个部署在ApacheTomcat6服务器上的Java web应用程序。该应用程序包含一个添加到类路径的info.properties文件,并具有几个硬编码值,这些值在运行时读取 现在,我需要从info.properties文件中删除某个值,并构建该值(一个字符串,指向同一Tomcat安装的bin文件夹的路径) 如何在运行时获取应用程序的工作目录,然后添加相对路径(从info.properties文件)以访问bin文件夹 谢谢请尝试以下代码以获取当前工作目录: public static S
info.properties
文件,并具有几个硬编码值,这些值在运行时读取
现在,我需要从info.properties
文件中删除某个值,并构建该值(一个字符串,指向同一Tomcat安装的bin
文件夹的路径)
如何在运行时获取应用程序的工作目录,然后添加相对路径(从info.properties
文件)以访问bin
文件夹
谢谢请尝试以下代码以获取当前工作目录:
public static String getCWD() {
File file;
int index;
String pathSeparator;
String cwd = null;
file = new File(".");
pathSeparator = File.separator;
index = file.getAbsolutePath().lastIndexOf(pathSeparator);
try {
cwd = file.getAbsolutePath().substring(0, index);
} catch (StringIndexOutOfBoundsException e) {
System.err.println("Caught Exception: " + e.getMessage() + "\n");
}
return cwd;
}
Tomcat主目录或Catalina目录存储在Java系统属性环境中。如果Java web应用程序部署到Tomcat web服务器中,我们可以使用以下命令获取Tomcat目录:
System.getProperty("catalina.base");
在这里,您可以在Tomcat文件夹中移动,并轻松打开文件箱可能重复的文件