Skip to main content

Command Palette

Search for a command to run...

DevOps Mini Project 2: Create & Push Java Maven App to GitHub (Amazon Linux 2)

Published
β€’3 min readβ€’View as Markdown
DevOps Mini Project 2: Create & Push Java Maven App to GitHub (Amazon Linux 2)

🎯 Objective:

  • Set up your Amazon Linux 2 environment with Java, Maven, and Git

  • Create a simple Java application using Maven

  • Initialize a Git repository

  • Push the code to GitHub

πŸ“¦ Part 1: Install Required Tools

πŸ”Ή Step 1: Update your Amazon Linux system

sudo yum update -y

πŸ”Ή Step 2: Install Java (Amazon Corretto 11)

sudo amazon-linux-extras enable corretto11
sudo yum install java-11-amazon-corretto -y

βœ… Verify Java installation

java -version

Expected output:

openjdk version "11.0.x"  Amazon Corretto

πŸ”Ή Step 3: Install Maven (Manually)

Amazon Linux doesn’t include Maven by default.

πŸ“₯ Download Maven

cd /opt
sudo curl -O https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

πŸ“‚ Extract Maven

sudo tar -xvzf apache-maven-3.8.8-bin.tar.gz
sudo ln -s apache-maven-3.8.8 maven

βš™οΈ Set Maven environment variables

sudo tee /etc/profile.d/maven.sh <<EOF
export M2_HOME=/opt/maven
export PATH=\${M2_HOME}/bin:\${PATH}
EOF

source /etc/profile.d/maven.sh

βœ… Verify Maven

mvn -version

Expected:

Apache Maven 3.8.8
Java version: 11.x.x

πŸ”Ή Step 4: Install Git

sudo yum install git -y

βœ… Verify Git

git --version

πŸ§ͺ Part 2: Create Java Maven Project

πŸ”Ή Step 5: Create a new Maven-based Java project

mvn archetype:generate -DgroupId=com.devopsseries.app \
-DartifactId=devops-mini-app \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false

Navigate into the project:

cd devops-mini-app

πŸ”Ή Step 6: Explore Project Structure

tree . -L 3

Expected:

.
β”œβ”€β”€ pom.xml
└── src
    β”œβ”€β”€ main
    β”‚   └── java
    └── test
        └── java

πŸ”Ή Step 7: Build & Test App

Compile:

mvn compile

Run unit tests:

mvn test

Build the .jar file:

mvn package

Check output:

ls target/

Expected:

devops-mini-app-1.0-SNAPSHOT.jar

πŸš€ Part 3: Push to GitHub

πŸ”Ή Step 8: Initialize Git Repo

git init
git add .
git commit -m "Initial commit - Java Maven app"

πŸ”Ή Step 9: Create a GitHub Repository

  1. Go to https://github.com

  2. Click "New" β†’ name it devops-mini-app

  3. Do NOT check β€œInitialize with a README”


πŸ”Ή Step 10: Push Code

git remote add origin https://github.com/YOUR_USERNAME/devops-mini-app.git
git branch -M main
git push -u origin main

βœ… Check GitHub Repo β€” your code should now be there!


🧹 Optional: Add .gitignore

To ignore target/ directory and keep your repo clean:

echo "target/" >> .gitignore
git add .gitignore
git commit -m "Add .gitignore"
git push

πŸ“Œ Final Summary:

TaskDone
Java installedβœ…
Maven installedβœ…
Git installedβœ…
Java app createdβœ…
App built & testedβœ…
Code pushed to GitHubβœ…

More from this blog

D

DevOps Dost

9 posts