# Deploy Spring Boot Application on AWS with script

### Step 1: Add maven dependecy

Use the following command to add maven dependency

```plaintext
sudo apt-get install maven
```

### Step 2: Clone the project

Clone your spring boot project into the directory

### Step 3: Clean Install

Run the following command to generate the jar file

```plaintext
mvn clean install
```

### Step 4: Run the jar file

Run the jar file inside target folder using the command

```plaintext
java -jar ./target/${jarname}.*.jar
```

### Step 5: Combine all into one File

Go to the path `/usr/local/bin` and create a file, lets call it `deploy`

```plaintext
sudo vi /usr/local/bin/deploy
```

insert the following lines

```plaintext
#!/bin/bash
fuser -k 8080/tcp
cd ~/project-folder
git pull && mvn clean install -DskipTests && nohup java -jar ./target/*-*.jar &
```

Save and close

Make Runnable with

```plaintext
sudo chmod +x deploy
```

now use `deploy` command to deploy the code at once
