Showing posts with label Apache Maven. Show all posts
Showing posts with label Apache Maven. Show all posts

Thursday, 4 July 2019

How does Maven work? | Apache Maven

How Does Maven Work? A Simple Guide for Beginners

🚀 Want to master Java and Maven?

Join the Ram N Java community for simplified tech tutorials!

SUBSCRIBE NOW

The Inner Workings of Apache Maven

Ever wondered what happens behind the scenes when you run a Maven command? It's like a well-oiled factory. Maven follows a specific set of rules and steps to turn your source code into a finished product, like a JAR or WAR file.

The Three Repositories

Maven doesn't just look for files on your computer. it uses a clever system of repositories to find exactly what your project needs:

  • Local Repository: This is a folder on your own machine where Maven stores everything it has downloaded before.
  • Central Repository: If Maven can't find a library locally, it goes to the "Central" hub on the internet to fetch it.
  • Remote Repository: Sometimes companies have their own private "vaults" for custom code that Maven can also access.

The Build Lifecycle

When you tell Maven to "build," it goes through a lifecycle. It starts by cleaning up old files, then compiles your code, runs tests to make sure everything works, and finally packages it up. Because this process is standardized, any developer can pick up your project and build it with a single command!

Explore More from Ram N Java

Check out these other helpful guides:

Monday, 20 July 2015

Apache Maven : Apache Maven Installation (Linux OS)

🚀 Want to Master Linux, Java & DevOps Build Tools?

Subscribe to Ram N Java for beginner-friendly programming tutorials, server setups, and automated build guides!

🔔 Subscribe to YouTube Channel

Maven Installation on Linux: Your Ultimate Step-by-Step Guide

Apache Maven is an essential open-source build automation and dependency management tool used across enterprise Java development and modern CI/CD pipelines. Installing Maven on a Linux distribution (such as Ubuntu, Debian, CentOS, Red Hat, or Amazon Linux EC2) enables you to compile code, package WAR and JAR artifacts, and manage project dependencies directly from the terminal.

1. Prerequisites: Verify Java (JDK) on Linux

Because Maven itself is written in Java and compiles Java code, having a properly configured Java Development Kit (JDK) is mandatory:

  • Check JDK Installation: Open your Linux terminal and execute:
    java -version
  • Verify JAVA_HOME: Ensure that your JAVA_HOME environment variable is set and accessible:
    echo $JAVA_HOME
  • If Java is not installed or the variable returns empty, install OpenJDK (version 8, 11, 17, or 21) before proceeding with the Maven setup.

2. Downloading the Apache Maven Archive

To obtain the latest stable release of Apache Maven:

  • Navigate to your temporary or installation directory (for instance, /tmp or /opt):
    cd /opt
  • Download the binary tarball archive (tar.gz) from Apache mirrors using wget:
    sudo wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
  • Extract the downloaded archive using the tar command:
    sudo tar -xvzf apache-maven-3.9.9-bin.tar.gz
  • (Optional) Create a symbolic link for convenient future version upgrades:
    sudo ln -s /opt/apache-maven-3.9.9 /opt/maven

3. Configuring Environment Variables (M2_HOME & PATH)

To execute mvn commands system-wide from any terminal location, configure your profile environment settings:

  • Create or edit a Maven environment profile script in /etc/profile.d/maven.sh:
    sudo nano /etc/profile.d/maven.sh
  • Add the following export statements into the file:
    export M2_HOME=/opt/maven
    export MAVEN_HOME=/opt/maven
    export PATH=${M2_HOME}/bin:${PATH}
  • Save the file and grant it executable permissions:
    sudo chmod +x /etc/profile.d/maven.sh
  • Reload the environment variables in your current session:
    source /etc/profile.d/maven.sh

4. Testing and Verifying Maven Installation

Validate that Maven is properly recognized by the Linux shell:

  • Run the version command:
    mvn -version
  • Expected Output: The terminal will print the installed Apache Maven version, Maven home directory, Java version, and Linux OS architecture details. Once visible, Maven is fully prepared to build your Java projects.

📺 Explore More Related Tutorials

Expand your Linux server administration and Java environment setup knowledge with these related tutorials from our channel:


Click here to watch on YouTube:
https://www.youtube.com/watch?v=zpOX8F_vW1k&list=UUhwKlOVR041tngjerWxVccw

Click here to download Apache Maven:
https://maven.apache.org/download.cgi


Click here to watch in Youtube :
https://www.youtube.com/watch?v=zpOX8F_vW1k&list=UUhwKlOVR041tngjerWxVccw

Click here to download Apache Maven :

http://maven.apache.org/

http://maven.apache.org/download.cgi

http://maven.apache.org/install.html


Linux Commands:
#wget http://apache.arvixe.com/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz

#tar xvf apache-maven-3.3.3-bin.tar.gz

#mvn –version

Maven Path Setup:
export M2_HOME=/opt/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Click the below Image to Enlarge
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
Apache Maven : Apache Maven Installation (Linux OS) 
See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Apache Maven : Apache Maven Installation (Windows OS)

    🚀 Want to Master Java Build Tools & Project Automation?

    Subscribe to Ram N Java for beginner-friendly coding tutorials, server configurations, and practical build guides!

    🔔 Subscribe to YouTube Channel

    Maven Installation on Windows Operating System: The Easy Step-by-Step Guide

    Apache Maven is the industry standard build automation and dependency management tool for Java applications. From downloading required libraries automatically via central repositories to running automated tests and packaging JAR or WAR files, Maven simplifies the complete project lifecycle. Setting it up on Windows takes only a few minutes when following the proper configuration steps.

    1. Prerequisites Before Installing Maven

    Before configuring Maven, ensure your system meets the basic requirements:

    • Java Development Kit (JDK): Maven requires JDK to compile Java source code. Make sure JDK (Java 8 or higher) is installed.
    • JAVA_HOME Environment Variable: Ensure your JAVA_HOME system environment variable points directly to your JDK directory (e.g., C:\Program Files\Java\jdk-17).
    • Verify Java: Open Command Prompt and run java -version and echo %JAVA_HOME% to confirm Java is ready.

    2. Downloading and Extracting Apache Maven

    Maven does not require a traditional installer; it runs directly from its binary directory:

    • Visit the official Apache Maven website: https://maven.apache.org/download.cgi.
    • Under the Files section, download the Binary zip archive (e.g., apache-maven-x.x.x-bin.zip).
    • Extract the downloaded zip archive to a clean, permanent directory such as C:\apache-maven or C:\Program Files\apache-maven.

    3. Setting Up MAVEN_HOME and PATH Environment Variables

    To allow the Windows Command Prompt to recognize Maven commands from any directory:

    • Press Win + S, search for Environment Variables, and open Edit the system environment variables.
    • Click the Environment Variables... button at the bottom right.
    • Under System variables, click New:
      • Variable name: MAVEN_HOME (or M2_HOME)
      • Variable value: Path to your extracted Maven folder (e.g., C:\apache-maven-3.9.x)
    • Under System variables, locate the Path variable and click Edit.
    • Click New and add: %MAVEN_HOME%\bin (or the direct path like C:\apache-maven-3.9.x\bin).
    • Click OK on all dialog boxes to save the configuration.

    4. Verifying the Maven Installation

    Test that the command-line interface communicates with Maven:

    • Open a fresh Command Prompt window (to reload system environment variables).
    • Run the command: mvn -version (or mvn -v).
    • You should see details showing the Apache Maven version, Maven home directory, Java version, and OS details. If displayed, Maven is fully configured and ready to use!

    Click here to watch on YouTube:
    https://www.youtube.com/watch?v=1HIURDQIoU4&list=UUhwKlOVR041tngjerWxVccw

    Click here to download Apache Maven:
    https://maven.apache.org/download.cgi

    Tutorials