This article is all about Apache Tomcat 9. We will cover installation and configuration of Apache Tomcat 9.
Apache Tomcat 9 Installation
Download Tomcat 9 from http://tomcat.apache.org/download-90.cgi#9.0.0.M4Â
First of all verify Java installation with the java -version command.
Go to $CATALINA_HOMEbin and run startup.bat or startup.sh based on your operating system.
If Tomcat is not running even though you have installed Java  8 then verify JAVA_HOME
C:apache-tomcat-9.0.0.M4bin>echo %java_home%
C:Program FilesJavajdk1.7.0_21
Let’s change the JAVA_HOME environment variable first to troubleshoot.
To change the JAVA_HOME environment variable visit our earlier post: Configuring JAVA_HOME in Windows, Linux , MAC OSÂ
Verify JAVA_HOME
C:apache-tomcat-9.0.0.M4bin>echo %java_home%
C:Program FilesJavajdk1.8.0_25
Now try to execute startup.bat (I am using Windows Operating system here)
Bingo!
Let’s verify in browser:Â http://localhost:8080/
Change Tomcat Default Port
<Connector port=”8080″ protocol=”HTTP/1.1″Â connectionTimeout=”20000″Â Â Â Â redirectPort=”8443″ />
Change the port number.
<Connector port=”9999″ protocol=”HTTP/1.1″Â connectionTimeout=”20000″Â Â Â Â redirectPort=”8443″ />
Go to $CATALINA_HOME/bin and run startup.bat or startup.sh based on your operating system.
Now we won’t be able to open Tomcat on 8080 port as we have changed it to 9999.
Let’s verify in browser:Â http://localhost:9999/
Bingo!!!
How to change the ROOT application
First of all Download Source code from https://github.com/spring-projects/spring-petclinic. Create a WAR file and copy it in the $CATALINA_HOME/webapps folder.
Go to $CATALINA_HOMEconf and open server.xml file in editor.
Find Host element from the XML file.
Before:
<Host name=”localhost”  appBase=”webapps” unpackWARs=”true” autoDeploy=”false”>
<!– SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html –>
<!–
<Valve className=”org.apache.catalina.authenticator.SingleSignOn” />
–>
<!– Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern=”common” –>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”
prefix=”localhost_access_log” suffix=”.txt”
pattern=”%h %l %u %t "%r" %s %b” />
</Host>
Configure Context root. put the context name in the docBase and add other details as shown below. Keep the autoDeploy value as False.
After:
<Host name=”localhost”  appBase=”webapps” unpackWARs=”true” autoDeploy=”false”>
<!– SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html –>
<!–
<Valve className=”org.apache.catalina.authenticator.SingleSignOn” />
–>
<Context path=”” docBase=”petclinic” debug=”0″ reloadable=”true”>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<!– Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern=”common” –>
<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”
prefix=”localhost_access_log” suffix=”.txt”
pattern=”%h %l %u %t "%r" %s %b” />
</Host>
Restart the Tomcat Server. Let’s verify in browser: http://localhost:9999/
Bingo!!!
Access Tomcat Manager App
When we use http://localhost:9999/and try to click on Manager App, it asks for authentication.
Go to $CATALINA_HOMEconf and open tomcat-users.xml
Add following  statements:
<role rolename=”manager-gui”/>
<role rolename=”manager-script”/>
<user username=”admin” password=”password” roles=”manager-gui,manager-script” />
Restart the Tomcat Server. Let’s verify in browser: http://localhost:9999/and try to click on Manager App, it asks for authentication. Give User name and Password.
Now verify Tomcat Web Application Manager
We can Start, Stop, Reload, Undeploy application from Tomcat Web Application Manager.
Bingo!!!