Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 1,txt

This file was deleted.

1 change: 0 additions & 1 deletion 2.txt

This file was deleted.

1 change: 0 additions & 1 deletion 3.txt

This file was deleted.

174 changes: 174 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
Installing the Java Development Kit (JDK) and Apache Maven on Ubuntu is a straightforward process thanks to Ubuntu's built-in package manager, `apt`.

Here is the step-by-step process to get your environment set up.

### Step 1: Update Your Package Index
Before installing new software, it is always a good practice to update your local package list to ensure you get the latest versions and dependencies.
Open your terminal and run:
```bash
sudo apt update
```

### Step 2: Install the JDK
Ubuntu provides a package called `default-jdk` which automatically installs the latest stable, long-term support (LTS) version of OpenJDK for your specific Ubuntu release.

1. **Install the package:**
```bash
sudo apt install default-jdk
```
*(Press `Y` and `Enter` if prompted to confirm the installation).*

2. **Verify the installation:**
Once the installation finishes, check that Java is installed correctly by checking its version:
```bash
java -version
```
You should also check that the Java compiler (`javac`) is installed:
```bash
javac -version
```

### Step 3: Install Apache Maven
Maven is also available directly from the default Ubuntu repositories.

1. **Install Maven:**
```bash
sudo apt install maven
```

2. **Verify the installation:**
Check that Maven was installed correctly and is recognizing your Java installation:
```bash
mvn -version
```
This command will output the Maven version, the Java version it is using, and the operating system details.

---

### Step 4: Set the `JAVA_HOME` Environment Variable (Recommended)
While many applications will find Java automatically, some build tools and IDEs require the `JAVA_HOME` environment variable to be set.

1. **Find your Java installation path:**
Run the following command to see where Java is installed:
```bash
sudo update-alternatives --config java
```
You will see a path that looks something like `/usr/lib/jvm/java-11-openjdk-amd64/bin/java`. Copy the path **up to the `/jre/bin/java` or `/bin/java` part**. (e.g., just `/usr/lib/jvm/java-11-openjdk-amd64`).

2. **Open your environment file:**
You can add this to your `.bashrc` file (which we discussed earlier!) so it loads every time you open a terminal.
```bash
nano ~/.bashrc
```

3. **Add the variable:**
Scroll to the very bottom of the file and add these two lines, replacing the path with the one you copied in step 1:
```bash
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
export PATH=$JAVA_HOME/bin:$PATH
```

4. **Save, exit, and apply:**
Save the file (`Ctrl+O`, `Enter`, `Ctrl+X` in Nano), and then apply the changes to your current session:
```bash
source ~/.bashrc
```
The Maven Build Lifecycle is the beating heart of how Maven works. If you understand this concept, you will understand exactly what Maven is doing behind the scenes when you run a command.

In simple terms, a **lifecycle** is a predefined sequence of steps (called **phases**) that Maven follows to build and distribute your project.

Maven actually has three built-in lifecycles:
1. **`default`:** The main lifecycle that handles compiling, testing, and packaging your code.
2. **`clean`:** Handles removing files generated by the previous build.
3. **`site`:** Handles generating project documentation into a website format.

Let's focus on the **`default` lifecycle**, as it is the one you will use 99% of the time.

### The Default Lifecycle Phases

The default lifecycle is made up of over 20 phases, but you only really need to know the major ones. They run in a strict, sequential order.



Here are the heavy hitters, in the exact order they execute:

* **`validate`:** Checks to make sure your project is correct and all necessary information (like dependencies) is available.
* **`compile`:** Translates your raw Java source code (`.java` files) into compiled bytecode (`.class` files).
* **`test`:** Runs your unit tests (usually using a framework like JUnit) to ensure your code behaves as expected. *Note: If a test fails, the build stops right here.*
* **`package`:** Takes all the compiled code and bundles it into a distributable format, like a `.jar` (Java ARchive) or `.war` (Web Application ARchive) file.
* **`verify`:** Runs any checks or integration tests on the packaged code to ensure it meets quality criteria.
* **`install`:** Copies your newly built `.jar` or `.war` file into your local Maven repository (a hidden folder on your computer at `~/.m2/repository`). This allows other Maven projects on your local machine to use it as a dependency.
* **`deploy`:** Copies the final package to a remote repository (like a company server or Maven Central) so other developers can download and use it.

---

### The Golden Rule of Maven: The Ripple Effect

Here is the most important thing to understand about the lifecycle: **When you tell Maven to run a specific phase, it will automatically run every single phase that comes *before* it.**

**Example 1:**
If you type `mvn compile` in your terminal, Maven runs:
1. `validate` -> 2. `compile`

**Example 2:**
If you type `mvn install`, Maven runs:
1. `validate` -> 2. `compile` -> 3. `test` -> 4. `package` -> 5. `verify` -> 6. `install`

This is why `mvn install` is one of the most common commands developers run. It handles the entire process from checking the code all the way to saving the final product on your machine.

### Combining Lifecycles

You will very frequently see developers run this command:
```bash
mvn clean install
```
This actually tells Maven to run two completely different lifecycles back-to-back. First, it runs the `clean` lifecycle to wipe away the `target/` directory (where old compiled files live). Then, it runs the `default` lifecycle all the way up to the `install` phase. It is the best way to ensure you are getting a fresh, pristine build.


## Step-by-step commands to run in your own Ubuntu terminal to get this Spring Boot application up and running perfectly.

Here is exactly what you need to do:

### Step 1: Clone the Repository
The URL you provided includes `/tree/main`, which is the web view. To clone it, we just use the base repository URL. Open your terminal and run:

```bash
git clone https://github.com/mindsparkist/springboot-java-poject.git
```

### Step 2: Navigate into the Project
Move into the directory that Git just created:

```bash
cd springboot-java-poject
```

### Step 3: Build the Project with Maven
Now, we will use the Maven installation we set up earlier to compile the code, run any tests, and package it into an executable `.jar` file.

```bash
mvn clean install
```
*(This might take a minute or two the first time, as Maven will download all the necessary Spring Boot dependencies from the internet.)*

### Step 4: Run the Application
Once the build is successful (you will see a big `BUILD SUCCESS` message), Maven will have placed your compiled `.jar` file inside a newly created `target/` directory.

To run it, use the `java -jar` command. You can usually use the wildcard `*` to catch the generated jar file without typing the full version number:

```bash
java -jar target/*.jar
```
*(If the wildcard doesn't work, you can type `ls target/` to see the exact name of the `.jar` file, and then run `java -jar target/exact-file-name.jar`).*

You should see the Spring Boot logo pop up in your terminal, followed by a bunch of log messages. Look for a line near the bottom that says something like `Tomcat started on port(s): 8080 (http)`.

### Step 5: Check the App on Port 8080
Once the application is running, open your web browser and navigate to:

**http://localhost:8080**

Alternatively, if you want to test it straight from another terminal window, you can open a new tab and run:
```bash
curl http://localhost:8080
```
13 changes: 0 additions & 13 deletions steps.md

This file was deleted.