Introduction
This project aims to automate the deployment of Java applications to an Apache Tomcat server using Jenkins. Instead of manually building and copying .war
files, we use a CI/CD pipeline where Jenkins pulls code from a Git repository, builds it using Maven, and deploys it to Tomcat automatically. This streamlines the development process, reduces human error, and enables faster, more reliable application delivery, following modern DevOps practices.
Why This Project?
Manual deployment of Java applications is time-consuming and error-prone. This project solves that by introducing automation using Jenkins, which ensures that every time code is updated, it is built, tested, and deployed automatically to a Tomcat server. It saves developer time, reduces bugs, and supports faster and more reliable software delivery — all of which are essential in modern DevOps and agile environments.
Prerequsities :
- Tomcat Server
- Jenkins Server
- A java Project
References
- Tomcat Setup : https://github.com/NikhilRaj-2003/java-web/blob/main/src/main/webapp/Installations%20/apache%20tomcat/Tomcat%20Installation%20on%20Amazon-Linux-2.md
- Jenkins : https://github.com/NikhilRaj-2003/java-web/blob/main/src/main/webapp/Installations%20/Jenkins/Jenkins%20Installation%20on%20Amazon-Linux-2.md
- Java Project : https://github.com/NikhilRaj-2003/java-web.git
Step — 1 : Install Git into your Jenkins server
- install git and check the git version .
# Become a root
sudo su -
# Install git.
yum install git -y
# Check Version of git.
git --version
- Open Jenkins in web-browser, click on manage jenkins then select Global Tool Configuration.
- Then under Global tool configuration , add git in Git Installations
- In git installations , click Add git then select git.
- Enter the Git name and path , later click apply and save
- Now we have successfully integrated Git with Jenkins . Then click on Global Tool Configuration , under that go to Maven installtions . After giving the details click on apply and save .
Now Maven is also successfully integrated with jenkins .
Steps — 2 : Install a Plugin called ‘Deploy to container ‘
- Go to manage jenkins > plugins > Available plugins > Deploy to container .
- Click on the restart jenkins after installations , after the installations the jenkins will restart and you need to enter the username and password .
step — 3 : Create a Global Credentials
- Go to Credentials > Select system > Select Global Credentials then click on Add Credentials .
- After clicking on add credentials , Enter the username and password
- Once your done giviing the details , then you can see the credentails you have created .
Step — 4: Create a Jenkins Job
- Head to Dashboard > New Item , then provide a name for the jenkins job and select freestyle project as project type .
- Enter the github repo and also change the branch name from master to main , because there is no master branch .
- Under Build steps > invoke top level maven targets , then provide maven command ‘ clean package’ . And there is no need to mention mvn as we give in the terminal , it automatically takes as mvn and then runs the command .
- In Post-build Actions click Add Post-build Actions and Select Deploy war/ear to container.
- Enter the details as following then click on apply and save.
Now Click on Build Now
The Build is Successfull .
Output of the project
Why to use Github Webhook ?
Using a GitHub webhook with Jenkins allows you to automatically trigger a build and deploy your Java web application whenever someone pushes code to your GitHub repository.
Step — 5 : Automate Build and Deploy using Github webhook
- Go to Github Account > Settings > Webhook , then create a webhook.
- Payload URL is public ip if jenkins server.
http://<public ip address>:8080/github-webhook/
- Set content type as application/JSON .
- Select Event Trigger as just the push event .e
- Then go to jenkins dashboard > tomcat-jenkins > configure > Triggers, there you need to enable the Github hook trigger for GITscm polling.
- Whenever there is a commit / changes made in the java web — application , then the webhook will automatically create build . Later click on Commit .
- After the Changes made when you click on commit , a build will be created in jenkins dashboard automatically where it builds and deploys the web application with (.war ) file.
- The changes made in github repository will be automatically changed in the web — application without any manual intervention . Webhook trigger whenever there is a commit in that repository .
Conclusion
This mini project successfully demonstrates a CI/CD pipeline where a Java web application is automatically built and deployed to Apache Tomcat using Jenkins. By integrating GitHub Webhooks, the pipeline is triggered instantly upon every code push, ensuring that the latest changes are continuously tested and deployed without manual intervention.
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.