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

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

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

Related

Eclipse + Tomcat 8 - application double deployment

I'm developing for Tomcat 8 under Eclipse Mars.
This is my application context in published server.xml:
<Context docBase="C:\automation\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\ROOT" path="" reloadable="false"/>
<Context docBase="AutomationWeb" path="/automation" reloadable="true" source="org.eclipse.jst.jee.server:AutomationWeb"/>
No other contexts defined there. But when I open tomcat manager app I see 2 contexts for my application:
One with "/AutomationWeb" path,
other with "/automation" path
My app has no context.xml
What I've discovered:
They share display name from my application's web.xml
My application can run on both paths.
The one with /AutomationWeb path is not actually reloadable
If I remove my application(Web Module) from Tomcat server in Eclipse, both entries disappear from tomcat manager app.
Deleting server in Eclipse and deleting contents of \workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\ didn't help.
How can I remove undesired application context with /AutomationWeb path? What configs should i check?
Solved it by changing publish directory from webapps to webappsauto. It seems the problem was in server.xml because of this statement:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

Exporting maven project from eclipse and its deployment on tomcat

I am using this tutorial and I did all the steps according to it. But I am stuck to the very end step that is
Build the project and deploy the war file in Tomcat. Start Tomcat and hit below URL.
URL: http://localhost:8080/springDemo-1.0/welcome.do
I done 'build project' in eclipse and I export the project as .war file to webapps of tomcat, but when I use the URL it says "HTTP Status 404" and "The requested resource (/springDemo-1.0/welcome.do) is not available." Please help
Better is to use m2e-wtp plugin for eclipse
Update site http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
After install update maven configuration (Maven -> Update Configuration). Now you can simple add WAR project to Tomcat instance configured in Eclipse WTP.
More about using this -> https://docs.sonatype.org/display/M2ECLIPSE/WTP+mini+howto
Maybe try manually loading the project into Tomcat. Go to http://localhost:8080 and click on "Tomcat Manager". At the bottom, upload your WAR and hit "Deploy". You should then be able to click on the link in the table, add the "/welcome.do", and see your page.
If you are denied access to the Tomcat manager, you might have to update the tomcat-users.xml in your Tomcat's conf folder (for example, see below).
<role rolename="manager-gui" />
<user username="admin" password="password" roles="manager-gui" />
With the above, you can access the manager using admin/password.

How to auto set crossContext in an Eclipse WTP Tomcat

How can I set the crossContext directive in the context of an web application so any WTP publish / deploy will set this correct to the generated Applications context.xml (conf/Catalina/localhost/appname.xml)
I tried to set it in the Servers context.xml as "default" but also generated a stub context.xml in the WEB-INF/context.xml of the web application, but nothing seems to help here ;/
The WEB-INF/context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true">
</Context>
Notes:
related to How to get a tomcat project path from different project in same tomcat by using java
http://olafsblog.sysbsb.de/tomcat-5-und-crosscontext-konfiguration/
http://www.eclipse.org/forums/index.php/t/51881/
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
http://www.eclipse.org/forums/index.php/t/50640/
It's simple but not perfect:
After adding the module to tomcat via wtp, open the WTP Tomcat server.xml (typically located in your workspace > Servers > Tomcat vX.X Server at localhost) and add attribute crossContext="true" to the <Context> tag of the corresponding web-module.
check "Publish module contexts to seperate XML files" in Tomcat WTP Frontend
Positive side-effects:
This will survive any "clean Tomcats working directory" or "clean project" actions
(still) Negative:
This will be overridden / removed if you change any WTP Tomcat options that affects server.xml like adding new modules, changing ports... After this action, you have to add it again.
There is still NO frontend option as like for reloadable or ContextPath ;/

Set Tomcat <Context> param from deployed Eclipse web application

I have an Eclipse Java web application that I am deploying to Tomcat 7 from within Eclipse 3.7. In my Eclipse server configuration at Servers > Tomcatv7-config > server.xml, I see the following line is added when I deploy my application:
<Context docBase="myapp" path="/myapp" reloadable="true" source="org.eclipse.jst.j2ee.server:myapp"/>
My question is this: is there any way for me to add a parameter to this <Context> element for a specific project?
What I need to do is add useHttpOnly=”false” in order for DWR to work properly in Tomcat 7. I understand the security risks with this, so please no lecture :)
You should be able to specify a context.xml in /META-INF/ within your WAR/Project which will trump the server.xml line:
In an individual file at /META-INF/context.xml inside the application
files. Optionally (based on the Host's copyXML attribute) this may be
copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to
application's base file name plus a ".xml" extension.

What is the "source" attribute of the Context element of an Apache Tomcat configuration file for?

It's somehow related to Eclipse. For example:
<Host>
<Context docBase="foo" path="/foo" reloadable="true"
source="org.eclipse.jst.j2ee.server:foo" />
</Host>
Eclipse WTP adds the source attribute to the project-related <Context> element to identify the location of the source code associated with the context (thus, the actual project in the workspace which has been deployed to this server from inside Eclipse).
If you wondered about this due to a warning during Tomcat's startup, since Tomcat 6.0.16 any "unrecognized" XML tags and attributes in the context.xml or server.xml will produce a warning about it during the startup, although there's actually no means of a DTD.
Just ignore it. Tomcat shall work fine and Eclipse is happy with it. It won't occur in real production environment with a worthfully WAR file.