Configuring Tomcat in Eclipse - Cognizant manuals/Spring MVC... · Configuring Tomcat in Eclipse ....
Transcript of Configuring Tomcat in Eclipse - Cognizant manuals/Spring MVC... · Configuring Tomcat in Eclipse ....
Configuring Tomcat in Eclipse
Table of Contents
1. Mapping JRE path
2. Adding Tomcat Instance
3. Configuring for Eclipse Run As option
4. Configuring for Manual Deployment of War
5. Adding GUI user entry for tomcat
6. Modifying Server ports
7. Increasing Time Outs
8. Disabling Automatic Publishing
Mapping JRE Path
The Runtime environment will be already present in your workspace. Please don’t
alter any setting other than the JDK option. This setting needs to be done only
once for a configuring a runtime environment for a workspace.
Go to windowspreferencesServerRuntime Environment.
The tomcat environment should be listed as shown below.
Select Tomcat and click on edit, the window below will be shown. From the drop
down select the option “JDK1.6.0_20” and click finish.
Note:
1. During your assessment
Don’t modify any other settings.
Once configured the settings will be available for any server instance added to the workspace
2. While practicing at your local desktop have a copy of tomcat server in your machine and click on
browse to select the Apache Tomcat Directory.
Adding Tomcat Instance
Once the JRE is configured a tomcat server instance can be added to the workspace. This is
done using the server console window. Open the server console window. If server console not
visible, you can either try changing the perspective to JEE or in windowsview option select
server.
From the server console right click and select new Server as shown below
The server selection window as shown below will appear. Select Tomcat 6.0 and click next and finally
finish the process. Don’t make any other configuration changes here.
Configuring for Eclipse Run as Option
This configuration meets the basic requirement running a web application from eclipse using
the right click run as option in Eclipse IDE. This is the simplest configuration. Once the server
instance is added as explained in the step2 it is ready to be run under this option.
Right Click the project and Select Run As option select the server and run it in the selected
server.
The web page will be displayed in the internal browser of eclipse.
The URL can be copied and pasted in an external browser also to see the output.
The limitation of this mode is we can’t access the tomcat console from the browser. Hence the
manual deployment of wars is not possible with this configuration.
Those who wish to build the war and deploy their application manually in the server can follow
the instructions given in step 4.
Configuring For Manual Deployment
In this mode we will see how we can configure the tomcat server settings so that the server
console can be accessed from the browser.
Complete step 1 and 2. After completing steps 2, double click the server listed in the server
console. This opens the server settings page as shown below.
In the above image you can see three option buttons for setting the server location (Shown
inside the red rectangle).
Select the second option which reads “Use Tomcat Installation (…)”.
Below the options field there will be a text box with label “Deploy Path” with a default value
“wtpwebapps”. Modify the path with the full path of the Tomcat’s webapp directory in your
system.
Normally it should be in the format “D:/jcauser/SDE_7_SSH/apache-tomcat-
6.0.36/wtpwebapps”. This is the path where tomcat is installed in your system please check for
the path once before you enter the value.
After the settings the page should look as shown below:
Note:
If the option for changing the settings is disabled,
1. Stop the server if the server is already running
2. Remove the applications which are already deployed in the server (can be done by
expanding the server from server console, right click the application and select remove).
3. After removing all the applications, right click the server and select clean.
If you want to manually manage the application deployment, redeployment etc. from the server console
you need to login to the server console using user name and password. This user name and password
needs to be configured in Tomcat-users.xml file as explained under the heading Adding GUI User.
Adding GUI User
To add a user who can manage the server from the server console in a browser the user name and
password can be configured in the tomcat-users.xml file present in the conf directory of the server. The
conf directory will be present under the apache-tomcat-6.0.36 directory.
For the assessment it can be found normally in
“D:/jcauser/SDE_7_SSH/apache-tomcat-6.0.36/conf”.
Open the tomcat-users.xml file and add the following entry
<role rolename="manager-gui"/>
<user password="tomcat" roles="manager-gui" username="tomcat"/>
Inside the <tomcat-users> tag. Note: Switching between manual deployment and eclipse run as deployment may result in the user setting getting rewritten in the tomcat-users.xml. So if you are facing any issues in logging to the server verify the GUI user entry in the tomcat-users.xml file.
Modifying Server Ports
If you face any exceptions while starting the server due to port already in use or similar reasons, the
server ports can be modified using the server properties page. Double click and open the server
properties page from the server console window and modify the port numbers. Save the settings and try
starting the server.
Increasing Time Outs
In case you face error in starting the server like “server didn’t start in 45s...” open the server
configuration file and increase the start and stop timings.
Disabling Automatic Publishing
By default eclipse automatically does an automatic publishing of the code to the server whenever a
resource change happens or application build is done. If you wish to disable automatic publishing, open
the server configuration file and modify the settings as shown below.