我需要仅使用 war 文件名作为输入来获取 war 文件的完整文件路径。我的意思是,返回值应该类似于 C:/PFiles/project/tomcat/sender/sender.war
我尝试使用以下方法获取路径,但它没有给我正确的路径。
File file = new File("sender.war");
String path = file.getAbsolutePath();
如何找到正确的路径?
最佳答案
尝试使用tomcat的系统属性。
String tomcatHome = System.getProperty( "catalina.base");
这将为您提供主目录,您可以在其中添加 tomcatHome+"webapps/yourwar"
。
关于java - 如何获取Web应用程序的war文件的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34254787/