# 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

```bash
sudo yum update -y
```

**🔹 Step 2: Install Java (Amazon Corretto 11)**

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

✅ **Verify Java installation**

```bash
java -version
```

Expected output:

```nginx
openjdk version "11.0.x"  Amazon Corretto
```

### 🔹 Step 3: Install Maven (Manually)

Amazon Linux doesn’t include Maven by default.

#### 📥 Download Maven

```bash
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

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

#### ⚙️ Set Maven environment variables

```bash
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**

```bash
mvn -version
```

**Expected:**

```yaml
Apache Maven 3.8.8
Java version: 11.x.x
```

### 🔹 Step 4: Install Git

```bash
sudo yum install git -y
```

### ✅ **Verify Git**

```bash
git --version
```

---

## 🧪 Part 2: Create Java Maven Project

### 🔹 Step 5: Create a new Maven-based Java project

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

**Navigate into the project:**

```bash
cd devops-mini-app
```

### 🔹 Step 6: Explore Project Structure

```bash
tree . -L 3
```

**Expected:**

```css
.
├── pom.xml
└── src
    ├── main
    │   └── java
    └── test
        └── java
```

### 🔹 Step 7: Build & Test App

Compile:

```bash
mvn compile
```

Run unit tests:

```bash
mvn test
```

Build the `.jar` file:

```bash
mvn package
```

Check output:

```bash
ls target/
```

Expected:

```pgsql
devops-mini-app-1.0-SNAPSHOT.jar
```

---

## 🚀 Part 3: Push to GitHub

### 🔹 Step 8: Initialize Git Repo

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

---

### 🔹 Step 9: Create a GitHub Repository

1. Go to [https://github.com](https://github.com)
    
2. Click **"New"** → name it `devops-mini-app`
    
3. Do **NOT** check “Initialize with a README”
    

---

### 🔹 Step 10: Push Code

```bash
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:

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

---

## 📌 Final Summary:

| **Task** | **Done** |
| --- | --- |
| Java installed | ✅ |
| Maven installed | ✅ |
| Git installed | ✅ |
| Java app created | ✅ |
| App built & tested | ✅ |
| Code pushed to GitHub | ✅ |
