Tomcat 7 在使用 Eclipse 时会覆盖 tomcat-users.xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16517659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:29:26  来源:igfitidea点击:

Tomcat 7 overrides the tomcat-users.xml when using Eclipse

eclipseconfigurationtomcat7

提问by nyxz

I am using Tomcat 7to deploy my web projects on. Also I am more comfortable when using the Eclipse interfaceto start and stop my Tomcat, so I've added it in the Eclipse's Serversand check the "Use Tomcat Installation" in Server Locations. One more thing that I use is the Tomcat's web Manager toolto deploy/undeploy the projects. As we know in order to use the Manager/html tool you have to sign in. The username and the password to authenticate are set in the tomcat-users.xml like this (in my file):

Tomcat 7用来部署我的网络项目。此外,我在使用Eclipse interface启动和停止我的 Tomcat时更舒服,所以我将它添加Eclipse's Servers"Use Tomcat Installation" in Server Locations. 我使用的另一件事是Tomcat's web Manager tool部署/取消部署项目。正如我们所知,为了使用 Manager/html 工具,您必须登录。用于身份验证的用户名和密码在 tomcat-users.xml 中设置如下(在我的文件中):

<role rolename="tomcat"/>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="standard"/>
<role rolename="admin"/>
<user username="tomcat-eclipse" password="tomcat-eclipse" roles="tomcat,manager,manager-script,standard,admin"/>
<user username="root" password="toor" roles="manager-gui" />  

Everything works fine until some moment in time (I'm not sure but maybe after several restarts or redeploys) the configuration that I've entered is flushed and the default (empty configuration) file overrides my customized config.

一切正常,直到某个时刻(我不确定,但可能在几次重新启动或重新部署之后)我输入的配置被刷新并且默认(空配置)文件覆盖了我的自定义配置。

Q: What causes the file to be overridden and how can I prevent that? Thanks.

问:是什么导致文件被覆盖,我该如何防止?谢谢。

Edit:
A: What I suggest based on some experiments is:

编辑:
A:我根据一些实验建议的是:

  • Variant one: Change the Tomcat 7's tomcat-users.xml file beforeyou add it to Eclipse. This is because I suspect when I was using the "Use Tomcat Installation" option Eclipse copied the old tomcat-users.xml in its metadata folder and when I change it later in Tomcat's install dir, it don't overrides it in the metadata. Then, for some reason, when running the server through Eclipse I suspect that it checks if the files are the same and if not then it overrides the tomcat-users.xml in the Tomcat's installation folder.
  • Use "Use workspace metadata" option. It is default. Then go to the Eclipse's Package explorer -> Your Tomcat Server -> tomcat-users.xml and change it from there. You can also copy the contents of your-tomcat-install-dir/webappsinto your-eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/in order to have the nice Tomcat html interface (as shown in Tutorial: Installing Tomcat 7 and Using it with Eclipse).
  • 变体一:在将Tomcat 7 添加到Eclipse之前更改Tomcat 7 的tomcat-users.xml 文件。这是因为我怀疑当我使用“使用 Tomcat 安装”选项时,Eclipse 将旧的 tomcat-users.xml 复制到了它的元数据文件夹中,当我稍后在 Tomcat 的安装目录中更改它时,它不会在元数据中覆盖它。然后,出于某种原因,当通过 Eclipse 运行服务器时,我怀疑它会检查文件是否相同,如果不相同,则它会覆盖 Tomcat 安装文件夹中的 tomcat-users.xml。
  • 使用“使用工作区元数据”选项。它是默认的。然后转到 Eclipse 的 Package explorer -> Your Tomcat Server -> tomcat-users.xml 并从那里更改它。您还可以复制your-tomcat-install-dir/webappsinto的内容your-eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/以获得漂亮的 Tomcat html 界面(如教程:安装 Tomcat 7 和使用 Eclipse 中所示)。

Try it. :)

尝试一下。:)

回答by Francisco López-Sancho

In Eclipse go to your Project 'Servers' in your 'Project Explorer' panel and inside folder 'Tomcat v7.0 Server at localhost-config'(this is the default name for a Tomcat server maybe yours is slightly different) change there tomcat-users.xml

在 Eclipse 中,转到“项目资源管理器”面板中的项目“服务器”和文件夹“localhost-config 处的 Tomcat v7.0 服务器”(这是 Tomcat 服务器的默认名称,可能您的名称略有不同)在那里更改 tomcat-用户文件



Project Explorer > 'Server's > Tomcat v7.0 Server at localhost-config > tomcat-users.xml

Project Explorer > 'Server's > Tomcat v7.0 Server at localhost-config > tomcat-users.xml

eclipse-screenshot

eclipse-screenshot