I'm learning Servlets programming, using Apache Tomcat 6 on a Ubuntu 8.10 machine, and I'm running with a very annoying issue -- apparently, related to caching.
我正在学习Servlets编程,在Ubuntu 8.10机器上使用Apache Tomcat 6,我正在运行一个非常烦人的问题 - 显然,与缓存有关。
This is what I'm doing: I write a servlet, put it in a nice directory structure and deploy it using the Tomcat Web Application Manager. It works as expected. Then I edit the servlet, recompile and try to access it again, but Tomcat keeps returning the same old version. Reloading the Application or even restarting the server does not work. The only thing that works is "Undeploying" the Application, then deploying it all over again.
这就是我正在做的:我编写一个servlet,将它放在一个漂亮的目录结构中,并使用Tomcat Web应用程序管理器进行部署。它按预期工作。然后我编辑servlet,重新编译并尝试再次访问它,但Tomcat仍然返回相同的旧版本。重新加载应用程序甚至重新启动服务器不起作用。唯一有效的是“取消部署”应用程序,然后再重新部署它。
I have to do this every single time I make any small change on my code. It sucks.
每次我对代码做一些小改动时,我都必须这样做。太糟糕了。
I'm sure there is a way around this, but I couldn't find the answer anywhere on the web (and I did search a lot). I would really appreciate any help. Thanks!
我确信有一种方法可以解决这个问题,但我无法在网络上的任何地方找到答案(我做了很多搜索)。我真的很感激任何帮助。谢谢!
5 个解决方案
#1
3
The advice from Adeel Ansari is flawed: you should never modify CATALINA_HOME/conf/context.xml with webapp-specific configuration. That's what your-webapp/META-INF/context.xml is for.
来自Adeel Ansari的建议存在缺陷:您永远不应该使用特定于webapp的配置修改CATALINA_HOME / conf / context.xml。这就是your-webapp / META-INF / context.xml的用途。
You should also never specify the "docBase" attribute of <Context>. You should also never specify the "path" attribute of <Context>.
您也不应该指定
The OP has several options:
OP有几种选择:
-
Use the manager to reload the web app (undeploy/redeploy should not be necessary: a simple reload should work) ( http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Reload_An_Existing_Application )
使用管理器重新加载Web应用程序(不需要取消部署/重新部署:简单的重新加载应该起作用)(http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Reload_An_Existing_Application)
-
Set the element in META-INF/context.xml to have reloadable="true" ( http://tomcat.apache.org/tomcat-6.0-doc/config/context.html )
在META-INF / context.xml中设置元素以使reloadable =“true”(http://tomcat.apache.org/tomcat-6.0-doc/config/context.html)
With all due respect to SO, if you need help with Tomcat, join the users' mailing list and get some real answers.
如果您需要有关Tomcat的帮助,请加入用户的邮件列表并获得一些真实的答案。
#2
2
I have encountered similar problems with Tomcat 5.5. I never figured out the root cause but I worked around it by deleting the folder corresponding to the webapp from %CATALINA_HOME%/work/Catalina/localhost. Its not a great solution but it avoids you having to undeploy/redeploy your whole application.
我遇到过与Tomcat 5.5类似的问题。我从来没有想出根本原因,但我通过删除%CATALINA_HOME%/ work / Catalina / localhost中与webapp相对应的文件夹来解决这个问题。它不是一个很好的解决方案,但它避免了你必须取消部署/重新部署整个应用程序。
#3
2
Under your TOMCAT_HOME/conf/, you will find a file named Context.xml. The content would look like below,
在您的TOMCAT_HOME / conf /下,您将找到名为Context.xml的文件。内容如下所示,
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/classes</WatchedResource>
</Context>
Both lines are uncommented here, you should uncomment both too. Its likely that you will have the 2nd one commented or might not have it at all. Try uncomment it, or add it in latter case. I am assuming you are deploying your app under TOMCAT_HOME/webapps.
这两行都没有注释,你也应该取消注释。您可能会对第二个评论或根本没有评论。尝试取消注释,或在后一种情况下添加它。我假设您正在TOMCAT_HOME / webapps下部署您的应用程序。
[Edited]
Try using docBase, and path attribure under your Context element. Below is the example
尝试在Context元素下使用docBase和path attribure。以下是示例
<Context docBase="path-to-WEB-INF" path="/your-app">
NOTE: Don't include WEB_INF
注意:不要包含WEB_INF
[Edited]
May be I am missing something. Check this out. Its the same, but much more clear and descriptive including few other options.
可能是我错过了什么。看一下这个。它是相同的,但更加清晰和描述性,包括其他一些选项。
#4
1
You don't say if you are using the ubuntu tomcat or a separate download from tomcat.apache.org. If you are using the ubuntu one, try to make it simpler with using a separate download. The standard download is very easy to administer and rather geared to working out of the box. It might be (I don't know) that the ubuntu one might be configured more towards production use, e.g. it might be somewhat hardened.
你没有说你是在使用ubuntu tomcat还是从tomcat.apache.org单独下载。如果您使用的是ubuntu,请尝试使用单独的下载更简单。标准下载非常易于管理,而且非常适合开箱即用。可能(我不知道)ubuntu可能更多地配置为生产用途,例如它可能有点硬化。
The recommended production setting for tomcat is just what you describe (e.g. no auto-deploy etc). The development setting is way easier to use.
tomcat的推荐生产设置就是您所描述的(例如,没有自动部署等)。开发设置更容易使用。
#5
0
If you use Netbeans then it automatically recompiles the class and injects it into the running webapp when you save the file. There are no additional steps involved, just hit save.
如果您使用Netbeans,它会自动重新编译该类,并在您保存文件时将其注入正在运行的webapp。没有其他步骤,只需点击保存即可。
#1
3
The advice from Adeel Ansari is flawed: you should never modify CATALINA_HOME/conf/context.xml with webapp-specific configuration. That's what your-webapp/META-INF/context.xml is for.
来自Adeel Ansari的建议存在缺陷:您永远不应该使用特定于webapp的配置修改CATALINA_HOME / conf / context.xml。这就是your-webapp / META-INF / context.xml的用途。
You should also never specify the "docBase" attribute of <Context>. You should also never specify the "path" attribute of <Context>.
您也不应该指定
The OP has several options:
OP有几种选择:
-
Use the manager to reload the web app (undeploy/redeploy should not be necessary: a simple reload should work) ( http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Reload_An_Existing_Application )
使用管理器重新加载Web应用程序(不需要取消部署/重新部署:简单的重新加载应该起作用)(http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html#Reload_An_Existing_Application)
-
Set the element in META-INF/context.xml to have reloadable="true" ( http://tomcat.apache.org/tomcat-6.0-doc/config/context.html )
在META-INF / context.xml中设置元素以使reloadable =“true”(http://tomcat.apache.org/tomcat-6.0-doc/config/context.html)
With all due respect to SO, if you need help with Tomcat, join the users' mailing list and get some real answers.
如果您需要有关Tomcat的帮助,请加入用户的邮件列表并获得一些真实的答案。
#2
2
I have encountered similar problems with Tomcat 5.5. I never figured out the root cause but I worked around it by deleting the folder corresponding to the webapp from %CATALINA_HOME%/work/Catalina/localhost. Its not a great solution but it avoids you having to undeploy/redeploy your whole application.
我遇到过与Tomcat 5.5类似的问题。我从来没有想出根本原因,但我通过删除%CATALINA_HOME%/ work / Catalina / localhost中与webapp相对应的文件夹来解决这个问题。它不是一个很好的解决方案,但它避免了你必须取消部署/重新部署整个应用程序。
#3
2
Under your TOMCAT_HOME/conf/, you will find a file named Context.xml. The content would look like below,
在您的TOMCAT_HOME / conf /下,您将找到名为Context.xml的文件。内容如下所示,
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/classes</WatchedResource>
</Context>
Both lines are uncommented here, you should uncomment both too. Its likely that you will have the 2nd one commented or might not have it at all. Try uncomment it, or add it in latter case. I am assuming you are deploying your app under TOMCAT_HOME/webapps.
这两行都没有注释,你也应该取消注释。您可能会对第二个评论或根本没有评论。尝试取消注释,或在后一种情况下添加它。我假设您正在TOMCAT_HOME / webapps下部署您的应用程序。
[Edited]
Try using docBase, and path attribure under your Context element. Below is the example
尝试在Context元素下使用docBase和path attribure。以下是示例
<Context docBase="path-to-WEB-INF" path="/your-app">
NOTE: Don't include WEB_INF
注意:不要包含WEB_INF
[Edited]
May be I am missing something. Check this out. Its the same, but much more clear and descriptive including few other options.
可能是我错过了什么。看一下这个。它是相同的,但更加清晰和描述性,包括其他一些选项。
#4
1
You don't say if you are using the ubuntu tomcat or a separate download from tomcat.apache.org. If you are using the ubuntu one, try to make it simpler with using a separate download. The standard download is very easy to administer and rather geared to working out of the box. It might be (I don't know) that the ubuntu one might be configured more towards production use, e.g. it might be somewhat hardened.
你没有说你是在使用ubuntu tomcat还是从tomcat.apache.org单独下载。如果您使用的是ubuntu,请尝试使用单独的下载更简单。标准下载非常易于管理,而且非常适合开箱即用。可能(我不知道)ubuntu可能更多地配置为生产用途,例如它可能有点硬化。
The recommended production setting for tomcat is just what you describe (e.g. no auto-deploy etc). The development setting is way easier to use.
tomcat的推荐生产设置就是您所描述的(例如,没有自动部署等)。开发设置更容易使用。
#5
0
If you use Netbeans then it automatically recompiles the class and injects it into the running webapp when you save the file. There are no additional steps involved, just hit save.
如果您使用Netbeans,它会自动重新编译该类,并在您保存文件时将其注入正在运行的webapp。没有其他步骤,只需点击保存即可。