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

北战南征 提交于 2019-12-01 04:35:26

问题


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). 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. 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


回答1:


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.



来源:https://stackoverflow.com/questions/5100182/is-there-a-way-to-get-the-absolute-path-of-the-context-root-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!