Java Build & Deployment Automation π This project automates the build and deployment of Java applications using Bash, Maven, and Apache Tomcat. It is designed as a DevOps mini-project to showcase automation, environment configuration, logging, and CI/CD integration.
Features β’ Automated build & deploy β packages Java applications with Maven and deploys them to Tomcat β’ Environment-aware configs β separate settings for Dev, Test, and Prod environments β’ Logging & error handling β all steps are timestamped and saved to log files β’ Cron integration β schedule automated deployments at specific times β’ Jenkins-ready β easily extendable into a CI/CD pipeline
Prerequisites Make sure you have the following installed: β’ Linux (Ubuntu, CentOS, or Amazon Linux EC2) β’ Java 11+ β’ Maven β’ Apache Tomcat Example (Amazon Linux 2): sudo yum install java-11-openjdk maven git -y
Download and extract Tomcat: wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.91/bin/apache-tomcat-9.0.91.tar.gz tar -xvzf apache-tomcat-9.0.91.tar.gz sudo mv apache-tomcat-9.0.91 /opt/tomcat chmod +x /opt/tomcat/bin/*.sh
Project Structure
java-deploy-automation/ βββ deploy.sh # Main Bash deployment script βββ configs/ β βββ dev.env # Dev environment config β βββ test.env # Test environment config β βββ prod.env # Prod environment config βββ README.md # Project documentation
Usage
-
Clone the Repo: git clone https://github.com/danizzy/java-deploy-automation.git cd java-deploy-automation
-
Run Deployment Script: ./deploy.sh dev # For Dev ./deploy.sh test # For Test ./deploy.sh prod # For Prod
-
Access the Application: http://:8080/
Automating with Cron Example: Run Test deployment daily at 1 AM: 0 1 * * * /home/ec2-user/java-deploy-automation/deploy.sh test >> /var/log/deploy_test_cron.log 2>&1
Jenkins Integration
Example Jenkins Pipeline (Jenkinsfile):
pipeline { agent any stages { stage('Checkout') { steps { git 'https://github.com/danizzy/java-deploy-automation.git' } } stage('Deploy to Dev') { steps { sh './deploy.sh dev' } } stage('Deploy to Test') { steps { sh './deploy.sh test' } } stage('Deploy to Prod') { steps { input "Deploy to Production?" sh './deploy.sh prod' } } } }
Future Improvements β’ Rollback support (restore last working WAR if deployment fails) β’ Dockerize Tomcat + Maven for container-based deployment β’ Extend pipeline with AWS services (EC2, S3, CodeDeploy)
Learning Outcomes β’ Bash scripting for automation β’ Maven build management β’ Tomcat application server deployment β’ Scheduling with cron β’ CI/CD concepts with Jenkins
Author π¨βπ» Author: Your Name (https://github.com/danizzy)