15
votes

I am using Tomcat 7 to deploy my web projects on. Also I am more comfortable when using the Eclipse interface to start and stop my Tomcat, so I've added it in the Eclipse's Servers and check the "Use Tomcat Installation" in Server Locations. One more thing that I use is the Tomcat's web Manager tool to 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):

<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:

  • Variant one: Change the Tomcat 7's tomcat-users.xml file before you 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/webapps into 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).

Try it. :)

1
Note: If you use the workspace metadata option, the default tomcat homepage (localhost:8080) is not available (see stackoverflow.com/questions/2280064/…) I just stumbled upon thisZuop

1 Answers

36
votes

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


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

eclipse-screenshot