Deploy Application Using WAR File On Jenkins
Deploy Application Using WAR File On Jenkins
Jenkins
Step-1: Launch an Ec2 instance using AWS
Add a name & choose Ami
Choose an instance type T2-micro
Add a key pair
Configure a security group
Configure storage
launch instance.
Step-2: Connect to AWS Console and install dependencies to configure jenkins.
Install java 21:
sudo rpm --import https://yum.corretto.aws/corretto.key
sudo curl -Lo /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo
sudo yum install -y java-21-amazon-corretto-devel
java -version
Note: sudo alternatives --config java.
Step-3: Go to /opt and download Maven. It is dependency to Compile,Test & Install the Code.
cd /opt
sudo curl -O https://downloads.apache.org/maven/maven-3/3.9.6/binaries/apache-
maven-3.9.6-bin.tar.gz
Extract and rename for simplicity
sudo tar -xvzf apache-maven-3.9.6-bin.tar.gz
sudo mv apache-maven-3.9.6 /opt/maven
Set up environment variables
sudo tee /etc/profile.d/maven.sh > /dev/null <<EOF
export M2_HOME=/opt/maven
export PATH=\$M2_HOME/bin:\$PATH
EOF
Make it executable and reload profile
sudo chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
Step-4: Setup jenkins in the same instance using jenkins.io repo.
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
Add required dependencies for the jenkins package
sudo yum install fontconfig java-21-openjdk
sudo yum install jenkins
sudo systemctl daemon-reload
sudo systemctl start jenkins
sudo systemctl status jenkins
Step-5:Access Jenkins
Open a web browser and navigate to http://your_server_ip_or_domain:8080. Follow the
on screen instructions to complete the setup.
Build the Job →you get job Success. (If not check the pom.xml plugins )
Eg:Output of the job
Step-8: Launch an another Ec2 instance using AWS for setup Tomcat
Add a name & choose Ami
Choose an instance type T2-micro
Add a key pair
Configure a security group
Configure storage
launch instance.
Step-9: Install java
sudo yum install java -y
Step 10: Download and Install Apache Tomcat Download Tomcat:
Navigate to the https://downloads.apache.org/tomcat/tomcat-9/v9.0.104/bin/ to find
the latest version.
Download the binary distribution for your system.
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.104/bin/apache-tomcat
9.0.104.tar.gz
Note: Copy the link of tar.gz file only.
Extract the Archive: tar -xvf apache-tomcat-9.0.104.tar.gz
STEP-11: Access Tomcat Open a web browser and navigate to
http://your_server_ip_or_domain:8080. Follow the on screen instructions to complete the
setup
After Setting up the Tomcat :
Navigate to jenkins
Go to Manage Jenkins → Install plugin called Deploy Container
Configure the Post build Actions Select Deploy war/ear to a container
1. WAR/EAR Files: target/*.war
2. Context path: ( name of application)
Add Tomcat Credentials and give Tomact url.
Eg:
Save it.
And trigger the job.
WAR file is deployed in Tomcat Application using jenkins .
Eg: (Given with name called phone-app)