有没有办法在tomcat中获得上下文根的绝对路径? [英] Is there a way to get the absolute path of the context root in tomcat?

查看:588
本文介绍了有没有办法在tomcat中获得上下文根的绝对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,经过很多阅读和研究,似乎tomcat正在运行另一个本身的实例,从而服务于我更新的应用程序的旧版本(或者以某种方式缓存了我的webapp的旧版本,那个。)
我在一个Windows机器上的eclipse中的应用程序上工作,并将它作为ROOT应用程序在Linux服务器上部署(将war文件重命名为ROOT.war)。
我想知道的是,如果有一种方法来找到tomcat正在服务的旧版本,通过获取tomcat来记录服务于较旧版本的应用程序的servlet的上下文根的输出。
由于更新的应用程序创建的任何文件在正确的目录中创建,因为应用程序实例不同,所以在创建后不久就无法访问这些文件。
任何帮助/提示将被欢迎

解决方案

要回答标题中的问题,让您的代码基本上做以下:

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

为了解决问题中描述的问题,关闭Tomcat并删除其 / work 目录,删除 / webapps 中的扩展WAR,并删除 / Catalina 子目录 / conf 目录(如果有),然后重新启动。


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

解决方案

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中获得上下文根的绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆