[英]How to get the path of web application's war file?
I need to get the full file path of war file using just the war file name as input. 我需要仅使用war文件名作为输入来获取war文件的完整文件路径。 I mean, the return value should be like C:/PFiles/project/tomcat/sender/sender.war 我的意思是,返回值应类似于C:/PFiles/project/tomcat/sender/sender.war
I have tried to get the path using the following, but it doesn't give me the correct path. 我尝试使用以下方法获取路径,但它没有给我正确的路径。
File file = new File("sender.war");
String path = file.getAbsolutePath();
How to find the correct path? 如何找到正确的路径?
Try using the system property of tomcat. 尝试使用tomcat的系统属性。 String tomcatHome = System.getProperty( "catalina.base" );
This will give you the home directory from there you can add tomcatHome+"webapps/yourwar"
. 这将为您提供主目录,您可以在其中添加tomcatHome+"webapps/yourwar"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.