简体   繁体   English

有没有办法在tomcat中获取上下文根的绝对路径?

[英]Is there a way to get the absolute path of the context root in tomcat?

I have a problem that, after a lot of reading and research, seems like tomcat is running another instance of itself and thus serving an old version of my updated app (or somehow has cached an older version of my webapp somewhere only serves that.) I work on the app in eclipse on a windows machine and deploy it on a Linux server as a ROOT app (Renaming the war file to a ROOT.war). 我有一个问题,经过大量的阅读和研究,似乎tomcat正在运行自己的另一个实例,因此服务于我更新的应用程序的旧版本(或者以某种方式缓存了我的webapp的旧版本只在那里服务。)我在windows机器上的eclipse中处理应用程序并将其作为ROOT应用程序部署在Linux服务器上(将war文件重命名为ROOT.war)。 What I'd like to know is if there's a way to locate the older version that tomcat is serving by getting tomcat to log an output of the context root of the servlet that's serving the older version of the app. 我想知道的是,有没有办法通过让tomcat记录服务于旧版本应用程序的servlet的上下文根的输出来找到tomcat所服务的旧版本。 As it stands it the moment any files created by the updated app get created in the right directory but because the app instances are different it can't access the files shortly after they're created. 现在看来,更新的应用程序创建的任何文件都是在正确的目录中创建的,但由于应用程序实例不同,因此无法在创建文件后立即访问这些文件。 Any help/hints would be welcomed 任何帮助/提示都会受到欢迎

To answer the question in the title, let your code basically do the following: 要回答标题中的问题,请让您的代码基本上执行以下操作:

System.out.println(getServletContext().getRealPath("/"));

To solve the problem described in the question, shutdown Tomcat and delete everything in its /work directory, delete the expanded WAR in /webapps and remove the /Catalina subdirectory of /conf directory (if any) and then restart. 要解决问题中描述的问题,请关闭Tomcat并删除其/work目录中的所有内容,删除/webapps展开的WAR并删除/conf目录的/Catalina子目录(如果有),然后重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM