Thursday, October 3, 2013

Deploy war in tomcat (run in eclipse)

I am using apache 7. When started in command prompt everything works as expected but if I start same from eclipse then I was not able to access it and find the

settings.

Looks like eclipse uses by default 'Use workspace metadata' and deploy path to 'wtpwebapps' in server settings. Follow the below steps to change these and you will be

able access localhost:8080 when you start server in eclipse.

1. In eclipse servers tab at bottom, right click, where you can see start, stop etc, and select properties.
2. In properties window, select general, then select Switch Location.
3. Now you can see Tomcat v7.0 Server at localhost, open it.
4a. If there are any modules deployed, temporarily remove them and close out tab to save this change, otherwise go directly to step 4c below.
4b. If you removed any modules, restart server after step 4a and proceed to step 4c.
4c. In server location, select radio button 'Use tomcat installation', and select 'webapps' in deploy path.
Save and start server in eclipse. Now you will be able to access the server.

5. You need to setup the admin user name /password in conf\tomcat-users.xml as below:

Add the below code in the xml:
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>

  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>

  <role rolename="admin"/>
  <user username="admin" password="admin" roles="manager,manager-gui"/>

6. Restart the server from eclipse.
7. access the tomcat using localhost:8080/manager -> enter the user : admin and password : admin.
8. Deploy the war file
9.  access it using localhost:8080/project_name

If the above procedure does not work, change the port number as below:
- double click on the tomcat 7.0... server in the eclipse to open overview screen
- change the default port (HTTP/1.1) for example 8080 to 8001 and do change other ports for AJP and tomcat admin as well.
- then follow the steps 1 to 9.