diff --git a/1,txt b/1,txt deleted file mode 100644 index 8b13789..0000000 --- a/1,txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/2.txt b/2.txt deleted file mode 100644 index 8b13789..0000000 --- a/2.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/3.txt b/3.txt deleted file mode 100644 index 8b13789..0000000 --- a/3.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/README.md b/README.md new file mode 100644 index 0000000..15ca22d --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/steps.md b/steps.md deleted file mode 100644 index eec6f54..0000000 --- a/steps.md +++ /dev/null @@ -1,13 +0,0 @@ -## https://www.youtube.com/@devopsshack -## Learn DevOps in 30 Days at https://www.youtube.com/watch?v=9q1DnI8MoIE&list=PLAdTNzDIZj_8BerYwx-rUjmVkj6A9vD9_&pp=gAQBiAQB -## To Build & Run This project, follow the steps. - ---> Clone the Project - ---> Go to Root directly of the project - ---> Run "mvn clean package" - ---> Run "java -jar target/jar_file_name.jar" - ---> Access the Application at IP:8080