A Maven, Jenkins, and Tomcat Trilogy: Automating Your Java Deployments


As a developer, you've probably spent countless hours manually building and deploying your Java applications. But what if there was a better way? A way to automate this entire process, making it faster, more reliable, and less prone to error? Well, you're in luck! In this article, we'll dive into the world of DevOps and show you how to integrate Jenkins, Maven, and Tomcat to create a seamless, automated deployment pipeline.
Understanding the Key Players
Before we get our hands dirty, let's briefly go over the roles of our three main characters:
Maven: A powerful build automation tool. It manages your project's lifecycle, from compiling source code to packaging it into a distributable format (like a
.war
file for web applications). Think of Maven as the workhorse that prepares your application for deployment.Jenkins: The orchestrator of our entire operation. Jenkins is an open-source automation server that automates the non-human parts of the software development process. It's the brain that ties everything together, triggering builds, running tests, and deploying your application.
Apache Tomcat: A popular open-source web server and servlet container. It's where our Java web application will actually run. Tomcat takes the packaged
.war
file and makes it accessible to users.
The Integration Blueprint 🏗️
Our goal is to create a pipeline that automatically builds our Java application using Maven and then deploys it to a Tomcat server whenever we push a change to our code repository. Here's a high-level overview of the process:
Code Commit: You make a change to your Java application code and push it to a version control system like Git.
Jenkins Trigger: Jenkins, configured to poll your repository, detects the new commit.
Maven Build: Jenkins triggers a Maven build to compile the code, run tests, and package it into a
.war
file.Tomcat Deployment: Jenkins uses a plugin to deploy the newly created
.war
file to your Tomcat server.Application Live: Your updated application is now live and accessible to users!
Step-by-Step Implementation
Ready to build this pipeline? Let's walk through the setup.
Step 1: Install and Configure Jenkins
First, you need a running Jenkins instance. You can install it on a server or even run it in a Docker container. Once installed, we need a crucial plugin for our deployment to work.
Don't know how to configure Jenkins Here's the step-by-step guide
What is a Jenkins Plugin?
A plugin in Jenkins is a tool or extension that adds new features and integrations to the core automation server. Think of it like an app on your smartphone; it adds a specific function that isn't included by default. Plugins are essential for customizing Jenkins to fit a project's needs, allowing it to integrate with thousands of external tools.
For this guide, we need the Deploy to Container Plugin.
Installing the Plugin
If you don't have this plugin, you can install it easily through the Jenkins web interface:
Navigate to Manage Jenkins -> Manage Plugins.
Click on the Available tab.
In the filter box, search for "Deploy to Container."
Check the box next to the "Deploy to Container Plugin" and click either "Install without restart" or "Download now and install after restart."
Step 2: Configure Maven on Jenkins
Navigate to Manage Jenkins -> Global Tool Configuration. Here, you can specify the path to your Maven installation. You can either let Jenkins handle the installation automatically or provide the path to an existing one.
Step 3: Create a Jenkins Job
Now, let's create the Jenkins job that will automate our process. We'll use a Freestyle project for this example.
Go to the Jenkins dashboard and click New Item.
Give your job a name (e.g.,
eShopWeb
) and select Freestyle project.In the job configuration, under the Source Code Management section, configure your Git repository. Provide the URL and any necessary credentials. For demonstration purposes, I've used a public repository. If you're working with private repositories, make sure to configure the necessary credentials. Feel free to share any feedback or suggestions in the comments.
Under Build Triggers, select GitHub hook trigger for GITScm polling.
Setting up the GitHub Webhook:
For this trigger to work, you need to configure a webhook in your GitHub repository that notifies your Jenkins server whenever relevant events occur.
Go to your GitHub Repository: Open your repository on the GitHub website.
Navigate to Settings: Click on the "Settings" tab.
Go to Webhooks: In the left-hand sidebar, click on "Webhooks".
Add a new webhook: Click the "Add webhook" button.
Payload URL: Enter the URL of your Jenkins server followed by
/github-webhook/
. For example, if your Jenkins server is running athttp://your-jenkins-ip:8080
, the Payload URL would behttp://your-jenkins-ip:8080/github-webhook/
. Note: Ensure your Jenkins server is reachable from GitHub (you might need to configure port forwarding or use a service like ngrok for local setups).Content type: Choose
application/json
.Secret (optional but highly recommended): Set a secret. This helps ensure that the webhook requests are actually coming from GitHub. Copy this secret, and in your Jenkins job configuration (under "GitHub hook trigger for GITScm polling"), click the "Advanced..." button and enter the same secret.
Which events would you like to trigger this webhook? You can choose specific events or select "Just the push event" for triggering builds on new code pushes. You can customize this based on your workflow.
Active: Ensure the "Active" checkbox is selected.
Add webhook: Click the "Add webhook" button.
In the Build section, add a "Invoke top-level Maven targets" build step.
Set the Maven Version to the one you configured earlier.
In the Goals field, enter
clean package
. This tells Maven to clean the project and then package it into a.war
file.
Finally, in the Post-build Actions section, add a "Deploy war/ear to a container" step.
Select Tomcat 9.x as the container.
Provide the path to your
.war
file, which is typicallytarget/*.war
.Enter the context path for your application (e.g.,
my-app
).Enter your Tomcat Manager credentials (username and password). This is how Jenkins authenticates with Tomcat to deploy the application.
Webhook Magic: CI/CD in Motion
Once your Jenkins job is configured and the GitHub webhook is set up, every push to your repository will automatically trigger a build. Jenkins listens for webhook events from GitHub, detects the change, and kicks off the pipeline without any manual intervention.
The pipeline will fetch the latest code, build the application using Maven, and deploy the resulting artifact directly to your Tomcat server. This hands-free automation ensures faster feedback loops and minimizes human error.
And this is just the foundation. You can evolve this pipeline by integrating automated unit and integration tests, static code analysis tools like SonarQube, and even multi-environment deployments—starting with staging and scaling to production. With Jenkins and GitHub working in sync, your CI/CD workflow becomes a launchpad for continuous innovation.
The Bigger Picture
This is the essence of Continuous Integration and Continuous Deployment (CI/CD). By automating the build and deployment process, you reduce manual effort, increase the speed of delivery, and minimize the risk of human error. It's a fundamental practice in modern software development and a skill that's highly sought after.
So go ahead, give it a try. Automate your deployments and spend less time on manual tasks and more time on what you love: building amazing applications!
Repo credits: Shaik Mustafa
Subscribe to my newsletter
Read articles from Divakar Chakali directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Divakar Chakali
Divakar Chakali
I'm a DevOps enthusiast and software engineer with 3.5 years of hands-on experience building scalable CI/CD pipelines, automating infrastructure, and streamlining deployment workflows. I specialize in tools like Jenkins, Maven, Docker, and Tomcat, and I love turning complex systems into elegant, maintainable solutions. On Hashnode, I share insights, tutorials, and real-world lessons from the trenches—whether it's debugging flaky builds, optimizing deployment strategies, or exploring the latest in cloud-native tech. My goal is to help developers and ops teams collaborate better, ship faster, and learn continuously.