Table of contents
Downloading and Configuring Tomcat:
Download Tomcat:
Search for the latest version of Tomcat on Google and obtain the download link. For example, you can find the link at https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz.
Navigate to Opt Directory:
sudo su - cd /opt
Download and Extract Tomcat:
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz tar -xvzf apache-tomcat-10.1.19.tar.gz
Rename Tomcat Directory:
mv apache-tomcat-10.1.19 tomcat
Start Tomcat Server:
cd /opt/tomcat/bin ./startup.sh
Access Tomcat Manager:
Open a web browser and navigate to
public_ip:8080
. Ensure that port 8080 is open in the security group of your instance.Update Context Configuration:
After receiving a 403 error when accessing the manager app, update the
context.xml
files:find / -name context.xml vi /opt/tomcat/webapps/host-manager/META-INF/context.xml vi /opt/tomcat/webapps/manager/META-INF/context.xml
Comment out the lines containing
<Valve class ...>
by adding<!--
at the beginning and-->
at the end.Configure Users for Manager App:
cd /opt/tomcat/conf/ vi tomcat-users.xml
Add the following users:
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="admin" password="admin@4253" roles="manager-gui, manager-script, manager-jmx, manager-status"/> <user username="deployer" password="deployer" roles="manager-script"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>
Restart Tomcat:
Create symbolic links for startup and shutdown scripts:
ln -s /opt/tomcat/bin/startup.sh /usr/local/bin/tomcatup ln -s /opt/tomcat/bin/shutdown.sh /usr/local/bin/tomcatdown
You can now start and stop Tomcat using
tomcatup
andtomcatdown
.
Integrating Tomcat with Jenkins:
Install "Deploy to container" Plugin:
Log in to Jenkins UI.
Navigate to
Manage Jenkins
>Manage Plugins
>Available
.Search for "Deploy to container" and install it without restarting.
Add Credentials:
Go to
Credentials
>System
>Global credentials (unrestricted)
>Add credentials
.Choose
Username with password
.Enter the following details:
Username: deployer
Password: (Provide the password)
ID: tomcat_deployer
Description: Use this credentials to deploy artifacts on Tomcat server
Create Jenkins Job:
Name: DemoDeployOnTomcat
Select
Maven Project
.SCM: Git (Add your repository URL)
Build:
Root POM: pom.xml
Goals and options: clean install
Post Build Actions:
Deploy war/ear to container
WAR/EAR files:
**/*.war
(Artifact built by Maven)Containers: Tomcat 9.x Remote
Credentials: Choose the credentials added earlier
Tomcat URL:
http://public_ip:8080
Build Jenkins Job:
Trigger the Jenkins job to build the project.
Verify Deployment:
Go to the Tomcat server's manager app.
Navigate to "List apps" and verify the deployed web application.
Following these steps will ensure the smooth setup and integration of Tomcat with Jenkins, allowing for efficient deployment of artifacts.