Skip to content

nagarjuna281/first-java-webapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Java Web Application Deployment with Jenkins & Tomcat on EC2

This project demonstrates how to deploy a simple Java web application using Jenkins and Apache Tomcat, hosted on two separate EC2 instances. The CI/CD pipeline automates code retrieval, build, and deployment using Maven and Jenkins.

Screenshot 2025-08-17 152524

🧱 Infrastructure Overview

Component Purpose
EC2 Instance #1 Jenkins Server (CI/CD)
EC2 Instance #2 Apache Tomcat Server

πŸ“¦ Application Repository

Source code is hosted on GitHub:
πŸ”— first-java-webapp


πŸ”§ Setup Instructions

1. Provision EC2 Instances

  • Launch two Ubuntu EC2 instances.
  • Assign Elastic IPs.
  • Open ports:
    • Jenkins: 8080
    • Tomcat: 8080
    • SSH: 22

2. Jenkins Setup (EC2 #1)

  • Access Jenkins at http://<JENKINS_EC2_IP>:8080

  • Install required plugins:

    • Git
    • Maven Integration
    • Deploy to Container
  • Configure Maven under Manage Jenkins β†’ Global Tool Configuration with name: mymaven

  • Add Jenkins credentials:

    • ID: tomcat
    • Username: tomcat
    • Password: ********

3. Tomcat Setup (EC2 #2)

πŸ” Configure Remote Deployment Access

  • Access Tomcat at http://<TOMCAT_EC2_IP>:8080

πŸ§ͺ Jenkins Pipeline Configuration

πŸ”§ Jenkinsfile

pipeline {
    agent any
    tools {
        maven "mymaven"
    }
    stages {
        stage('Code from GitHub') {
            steps {
                git branch: 'main', url: 'https://github.com/nagarjuna281/first-java-webapp.git'
            }
        }
        stage('Build') {
            steps {
                sh 'mvn clean package'
            }
        }
        stage('Deploy to Tomcat') {
            steps {
                deploy adapters: [
                    tomcat9(
                        alternativeDeploymentContext: '', 
                        credentialsId: 'tomcat', 
                        path: '', 
                        url: 'http://<TOMCAT_EC2_IP>:8080'
                    )
                ], 
                contextPath: 'myapp', 
                war: 'target/*.war'
            }
        }
    }
}

πŸ› οΈ Creating the Jenkins Pipeline Job

  1. Open Jenkins dashboard.
  2. Click New Item.
  3. Enter a name (e.g., first-java-webapp) and select Pipeline, then click OK.
  4. Scroll down to the Pipeline section.
  5. Choose Pipeline script and paste the Jenkinsfile code above.
  6. Click Save.
  7. Click Build Now to trigger the pipeline.

πŸš€ Deployment Flow

  1. Jenkins pulls code from GitHub.
  2. Maven builds the .war file.
  3. Jenkins deploys the .war to Tomcat using the Deploy to Container plugin.

🌐 Access the Application

Once deployed, your app will be available at:
http://<TOMCAT_EC2_IP>:8080/myapp

Untitled

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages