To make things easier you will install Tomcat inside your home directory.
I assume that you already installed Java on your box,
if not now is the time to do this. To instal Java follow tutorial at webupd8.
Let’s check if everything is OK by starting Tomcat and opening
http://localhost:8080 in your favorite browser:
You should see Tomcat welcome page:
Now we will add an administrator account on Tomcat server. This is not needed
by Eclipse but it may come in handy when you will later want to play
Now you must add the following line to tomcat-users.xml file:
Here we are creating admin user with 1234 password and we give him (or her)
permissions to administration gui.
Let’s start Tomcat again (using ./catalina.sh run) and check that
we can visit Tomcat manager page (located at http://localhost:8080/manager/html):
Configuring Eclipse Neon
Before we start check that you have following plugins installed:
Now we must create new Server Runtime Environment. Go to Preferences -> Server -> Runtime Environment -> Add…
Then specify path to your Tomcat installation (/home/user_name/tomcat)
and optionally JRE (use Oracle Java 8 if available) and click Finish.
There is no Tomcat 8.5 in my wizard (if you completed previous steps skip this secion)
There is a bug in Eclipse that prevents some users from seeing
Tomcat 8.5 option in their wizards:
The solution is simple, we manually change Tomcat version number say
from 8.5.6 to 220.127.116.11.6 and this will allow us to use newer Tomcat version
with buggy Eclipse.
More details can be found in this SO question.
Following script will will patch Tomcat server:
After running script try to start Tomcat server to check if it is working.
Then if everything is OK create new Runtime Environment in Eclipse using Tomcat 8 option.
Starting Tomcat from Eclipse
Open Servers window (press Ctrl+3 and write in search box Servers).
Use link in Servers window to open New Server wizard and create a new server:
You should see new server created:
Click on server and choose Clean option, then click again and select Start.
If you have Tomcat running in terminal (./catalina.sh run) stop it before
you start Tomcat via Eclipse. Console window should display various
log entries from starting Tomcat. Now click on server and select Stop.
Now it’s time to restart Eclipse and check if everything works after
Creating simple Spring MVC app
We will create simple Spring MVC application to check if everything is working.
Let’s start by creating new Maven project (New Project -> Maven Project and check Create simple project):
Don’t forget to select WAR as packaging method.
Open your POM file in XML editor and add following lines to it:
Then let’s add four more files to our project:
Now click on pom.xml select Run As -> Maven install, this should
create hellotomcat-0.0.1-SNAPSHOT.war file in target directory.
Click on project select Run As -> Run Configurations, then select Apache Tomcat and press New button.
Click Apply and Close.
Click on project select Run As -> Run on Server:
Go to http://localhost:8080/hellotomcat/ and check if you see greetings.
Now open HomeController file change text and save changes, after a few
seconds refresh browser page - you should see your new text.