This guide provides step-by-step instructions to build, package, and deploy the Emraay Bank Java web application. We'll start with a student-friendly manual deployment approach to help you understand the fundamentals, then progress to professional artifact repository deployment using Nexus.
- Build your Java application with Maven
- Manual Deployment - Copy WAR file directly to Tomcat (understand the basics)
- Artifact Repository - Learn about Nexus and professional deployment practices
- Automation - Create scripts and CI/CD pipelines
This progressive approach helps you understand both the "how" and the "why" behind modern deployment practices!
- Java Development Kit (JDK) 17 or higher
- Apache Maven 3.6 or higher
- Nexus Repository Manager running on EC2
- Tomcat server running on EC2
- Access to both EC2 instances
If you don't have Java installed, install OpenJDK 17:
On Ubuntu/Debian:
sudo apt update
sudo apt install openjdk-17-jdk -yOn CentOS/RHEL:
sudo yum install java-17-openjdk-devel -yVerify Java Installation:
java -version
javac -versionOn Ubuntu/Debian:
sudo apt update
sudo apt install maven -yOn CentOS/RHEL:
sudo yum install maven -yVerify Maven Installation:
mvn -versionIf you prefer to install Maven manually or need a specific version:
# Create Maven directory
sudo mkdir -p /opt/maven
cd /opt/maven
# Download Maven (check https://maven.apache.org/download.cgi for latest version)
sudo wget https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
# Extract Maven
sudo tar xzf apache-maven-3.9.6-bin.tar.gz
# Create symlink for easy access
sudo ln -s apache-maven-3.9.6 maven
# Set environment variables
echo 'export MAVEN_HOME=/opt/maven/maven' | sudo tee -a /etc/environment
echo 'export PATH=$MAVEN_HOME/bin:$PATH' | sudo tee -a /etc/environment
# Apply environment variables
source /etc/environment
# Verify installation
mvn -versionCreate Maven settings directory:
mkdir -p ~/.m2Create a basic settings.xml file:
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<mirrors>
<!-- Use Maven Central as default mirror -->
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<name>Maven Central</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
</mirrors>
</settings>
EOFRun these commands to ensure everything is properly installed:
# Check Java
java -version
echo "Java installation: β
"
# Check Maven
mvn -version
echo "Maven installation: β
"
# Test Maven with a simple command
mvn help:system
echo "Maven functionality: β
"You should see output similar to:
openjdk version "17.0.x" 2023-xx-xx
Apache Maven 3.9.x
Maven home: /usr/share/maven
Java version: 17.0.x, vendor: Eclipse Adoptium
π Great! You now have Java and Maven installed and ready to build Java applications!
emraay-bank-app/
βββ pom.xml
βββ src/
β βββ main/
β βββ java/
β β βββ com/
β β βββ emraay/
β β βββ bank/
β β βββ model/
β β β βββ Customer.java
β β β βββ Transaction.java
β β βββ servlet/
β β β βββ LoginServlet.java
β β β βββ DashboardServlet.java
β β βββ service/
β β βββ CustomerService.java
β βββ webapp/
β βββ WEB-INF/
β β βββ web.xml
β βββ css/
β β βββ style.css
β βββ js/
β β βββ main.js
β β βββ login.js
β β βββ dashboard.js
β βββ index.html
β βββ login.jsp
β βββ dashboard.jsp
git clone https://github.com/emraay-devops/emraay-bank-app.git
cd emraay-bank-appmvn clean compilemvn testmvn clean packageThis will create a WAR file in the target/ directory: emraay-bank-app.war
After building, you'll find the WAR file in the target/ directory:
ls -la target/
# You should see: emraay-bank-app.warOption A: Using SCP (if Tomcat is on a remote server)
# Copy WAR file to your Tomcat server
scp target/emraay-bank-app.war tomcat@your-tomcat-server-ip:/tmp/Option B: Direct Copy (if Tomcat is on the same machine)
# Copy WAR file directly to Tomcat webapps directory
sudo cp target/emraay-bank-app.war /opt/tomcat/webapps/# Set ownership to tomcat user
sudo chown tomcat:tomcat /opt/tomcat/webapps/emraay-bank-app.war
# Set appropriate permissions
sudo chmod 644 /opt/tomcat/webapps/emraay-bank-app.warsudo systemctl restart tomcat# Check Tomcat status
sudo systemctl status tomcat
# Check if application is deployed
ls -la /opt/tomcat/webapps/
# You should see:
# - emraay-bank-app.war (WAR file)
# - emraay-bank-app/ (extracted application directory)Navigate to: http://your-tomcat-server-ip:8080/emraay-bank-app/
- Username:
william.lycee - Password:
password123
- Home Page: Should display Emraay Bank welcome page
- Login Page: Should show login form with demo credentials
- Dashboard: Should display William Lycee's account information
- Account Balance: Should show $9,573.00 CAD
- Transactions: Should display 6 demo transactions
π Congratulations! You've successfully deployed your first Java web application!
Now that you've experienced manual deployment, let's learn about artifact repositories and why they're important in professional environments.
An artifact repository is a centralized storage system for software artifacts (like your WAR file). Think of it as a "library" where you can:
- Store your application versions
- Share artifacts with team members
- Download dependencies
- Track what versions are deployed where
- Version Control: Keep track of different versions
- Team Collaboration: Share artifacts with your team
- Automation: Enable CI/CD pipelines
- Security: Control who can access what
- Dependencies: Manage third-party libraries
Edit your Maven settings.xml file (usually located at ~/.m2/settings.xml):
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>your-nexus-password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://your-nexus-server-ip:8081/repository/maven-public/</url>
</mirror>
</mirrors>
</settings>Update the distributionManagement section in pom.xml:
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Release Repository</name>
<url>http://your-nexus-server-ip:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Nexus Snapshot Repository</name>
<url>http://your-nexus-server-ip:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>mvn clean deployThis command will:
- Clean the project
- Compile the source code
- Run tests
- Package the application
- Deploy the artifact to Nexus Repository
- Open Nexus web interface:
http://your-nexus-server-ip:8081 - Login with admin credentials
- Navigate to Browse β maven-releases
- Verify that
com.emraay.bank:emraay-bank-app:1.0.0is listed
On your Tomcat server (EC2 instance):
# Create deployment directory
sudo mkdir -p /opt/deployments
cd /opt/deployments
# Download WAR file from Nexus
wget http://your-nexus-server-ip:8081/repository/maven-releases/com/emraay/bank/emraay-bank-app/1.0.0/emraay-bank-app-1.0.0.war# Copy WAR file to Tomcat webapps directory
sudo cp emraay-bank-app-1.0.0.war /opt/tomcat/webapps/
# Set proper permissions
sudo chown tomcat:tomcat /opt/tomcat/webapps/emraay-bank-app-1.0.0.war
sudo chmod 644 /opt/tomcat/webapps/emraay-bank-app-1.0.0.warsudo systemctl restart tomcat# Check Tomcat status
sudo systemctl status tomcat
# Check if application is deployed
ls -la /opt/tomcat/webapps/You should see:
emraay-bank-app-1.0.0.war(WAR file)emraay-bank-app-1.0.0/(extracted application directory)
Navigate to: http://your-tomcat-server-ip:8080/emraay-bank-app-1.0.0/
- Username:
william.lycee - Password:
password123
- Home Page: Should display Emraay Bank welcome page
- Login Page: Should show login form with demo credentials
- Dashboard: Should display William Lycee's account information
- Account Balance: Should show $9,573.00 CAD
- Transactions: Should display 6 demo transactions
π Excellent! You've now experienced both manual deployment and artifact repository deployment!
Create a script deploy.sh for automated deployment:
#!/bin/bash
# Configuration
NEXUS_URL="http://your-nexus-server-ip:8081"
TOMCAT_HOME="/opt/tomcat"
APP_NAME="emraay-bank-app"
VERSION="1.0.0"
echo "Starting deployment process..."
# Step 1: Build application
echo "Building application..."
mvn clean package
if [ $? -ne 0 ]; then
echo "Build failed!"
exit 1
fi
# Step 2: Deploy to Nexus
echo "Deploying to Nexus..."
mvn deploy
if [ $? -ne 0 ]; then
echo "Nexus deployment failed!"
exit 1
fi
# Step 3: Download from Nexus
echo "Downloading from Nexus..."
wget -O ${APP_NAME}-${VERSION}.war \
${NEXUS_URL}/repository/maven-releases/com/emraay/bank/${APP_NAME}/${VERSION}/${APP_NAME}-${VERSION}.war
# Step 4: Deploy to Tomcat
echo "Deploying to Tomcat..."
sudo cp ${APP_NAME}-${VERSION}.war ${TOMCAT_HOME}/webapps/
sudo chown tomcat:tomcat ${TOMCAT_HOME}/webapps/${APP_NAME}-${VERSION}.war
# Step 5: Restart Tomcat
echo "Restarting Tomcat..."
sudo systemctl restart tomcat
# Step 6: Wait for deployment
echo "Waiting for deployment to complete..."
sleep 30
# Step 7: Verify deployment
echo "Verifying deployment..."
if curl -f http://localhost:8080/${APP_NAME}-${VERSION}/ > /dev/null 2>&1; then
echo "Deployment successful!"
echo "Application available at: http://your-tomcat-server-ip:8080/${APP_NAME}-${VERSION}/"
else
echo "Deployment verification failed!"
exit 1
fi
echo "Deployment completed successfully!"chmod +x deploy.sh./deploy.shCreate a Jenkinsfile in your project root:
pipeline {
agent any
environment {
NEXUS_URL = 'http://your-nexus-server-ip:8081'
TOMCAT_SERVER = 'your-tomcat-server-ip'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('Package') {
steps {
sh 'mvn clean package'
}
}
stage('Deploy to Nexus') {
steps {
sh 'mvn deploy'
}
}
stage('Deploy to Tomcat') {
steps {
sh '''
wget -O emraay-bank-app-1.0.0.war \
${NEXUS_URL}/repository/maven-releases/com/emraay/bank/emraay-bank-app/1.0.0/emraay-bank-app-1.0.0.war
scp emraay-bank-app-1.0.0.war tomcat@${TOMCAT_SERVER}:/tmp/
ssh tomcat@${TOMCAT_SERVER} '
sudo cp /tmp/emraay-bank-app-1.0.0.war /opt/tomcat/webapps/
sudo chown tomcat:tomcat /opt/tomcat/webapps/emraay-bank-app-1.0.0.war
sudo systemctl restart tomcat
'
'''
}
}
stage('Health Check') {
steps {
sh '''
sleep 30
curl -f http://${TOMCAT_SERVER}:8080/emraay-bank-app-1.0.0/ || exit 1
'''
}
}
}
post {
success {
echo 'Deployment successful!'
}
failure {
echo 'Deployment failed!'
}
}
}Monitor Tomcat logs for application status:
# View Tomcat logs
sudo tail -f /opt/tomcat/logs/catalina.out
# View application-specific logs
sudo tail -f /opt/tomcat/logs/localhost.$(date +%Y-%m-%d).logCreate a health check script health-check.sh:
#!/bin/bash
APP_URL="http://localhost:8080/emraay-bank-app-1.0.0/"
EXPECTED_STATUS="200"
echo "Performing health check..."
# Check if application responds
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" $APP_URL)
if [ "$HTTP_STATUS" = "$EXPECTED_STATUS" ]; then
echo "β
Application is healthy (HTTP $HTTP_STATUS)"
exit 0
else
echo "β Application health check failed (HTTP $HTTP_STATUS)"
exit 1
fi# Check Java version
java -version
# Check Maven version
mvn -version
# Clean Maven cache
mvn clean# Check Tomcat status
sudo systemctl status tomcat
# Check Tomcat logs
sudo tail -f /opt/tomcat/logs/catalina.out
# Check application logs
sudo tail -f /opt/tomcat/logs/localhost.$(date +%Y-%m-%d).log# Test Nexus connectivity
curl -I http://your-nexus-server-ip:8081
# Check Maven settings
cat ~/.m2/settings.xmlIf deployment fails, rollback to previous version:
# Stop Tomcat
sudo systemctl stop tomcat
# Remove current deployment
sudo rm -rf /opt/tomcat/webapps/emraay-bank-app-1.0.0*
# Deploy previous version (if available)
sudo cp /opt/backups/emraay-bank-app-previous.war /opt/tomcat/webapps/
# Start Tomcat
sudo systemctl start tomcat- Change default passwords
- Use HTTPS in production
- Implement proper authentication
- Regular security updates
- Configure firewall rules
- Use SSH keys for authentication
- Regular system updates
- Monitor access logs
This guide provides a complete deployment pipeline for the Emraay Bank application:
- Build: Maven compilation and packaging
- Package: WAR file creation
- Deploy to Nexus: Artifact storage and management
- Deploy to Tomcat: Application deployment on EC2
- Verify: Health checks and monitoring
The application is now ready for production use with proper CI/CD integration, monitoring, and security measures in place.
- Set up automated backups
- Configure SSL certificates
- Implement monitoring and alerting
- Set up log aggregation
- Configure load balancing (if needed)
- Implement blue-green deployments