Home Java javaTutorial Detailed explanation of Maven installation and configuration steps

Detailed explanation of Maven installation and configuration steps

Jan 05, 2024 am 08:09 AM
- Install - Configuration maven configuration - Step analysis

Detailed explanation of Maven installation and configuration steps

Detailed step-by-step analysis of Maven installation and configuration

With the rapid development of software development, Maven has become one of the preferred tools for Java project management. It provides a set of specifications and a methodology that makes project construction, dependency management, and release simpler and more efficient. This article will detail how to install and configure Maven, and provide some common code examples.

Step one: Download and install Maven

  1. Download the latest version of Maven on the Maven official website (https://maven.apache.org/download.cgi) and choose the appropriate one binary file (in most cases a .tar.gz or .zip file).
  2. Extract the downloaded file to the directory where you want to install Maven, for example: /usr/local/apache-maven.

Step 2: Configure environment variables

  1. Open a terminal and edit the .bash_profile file (if you are using Linux or Mac OS X) or edit the system environment variables ( If you are using Windows).
  2. Add the following lines to the end of the file:
export M2_HOME=/usr/local/apache-maven
export PATH=$PATH:$M2_HOME/bin
Copy after login
  1. Save the file and exit the editor.
  2. Execute the following command in the terminal to make the environment variables take effect:
source .bash_profile
Copy after login

Step 3: Verify the installation

  1. Open the terminal and execute the following command:
mvn -v
Copy after login
  1. If the Maven version information is displayed, the installation is successful.

Step 4: Configure Maven repository
Maven uses the repository (Repository) to store project dependencies. By default, Maven will save downloaded dependencies in the .m2 folder in the user's home directory. But you can also choose other directories as the location of the warehouse.

  1. Open the conf folder in the Maven installation directory.
  2. Find and edit the settings.xml file.
  3. Find the tag and add the following content inside it:
<mirror>
  <id>nexus</id>
  <url>http://your-nexus-repo/repository/maven-public/</url>
  <mirrorOf>*</mirrorOf>
</mirror>
Copy after login
  1. Replace the URL in the above code with the warehouse address of your choice.
  2. Save the file and exit the editor.

Step 5: Create a new project

  1. Open a terminal and go to the directory where you want to create a new project.
  2. Execute the following command to create a basic Maven project:
mvn archetype:generate -DgroupId=com.example -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Copy after login
  1. This command will create a project containing pom.xml and src/main/java/com/example /Basic project structure of the App.java file.
  2. Go to the project folder you just created.

Step 6: Build the project

  1. Execute the following command in the terminal:
mvn compile
Copy after login
  1. This command will compile the project source code and output the compilation results to the target folder.

Step 7: Run the project

  1. Execute the following command in the terminal:
mvn exec:java -Dexec.mainClass="com.example.App"
Copy after login
  1. This command will run the App .main method in java and output the results.

Through the above steps, you have successfully installed and configured Maven and created a basic project. Of course, this is just the tip of the Maven iceberg, it also provides many other features and plug-ins that can help you better manage and build projects.

Summary:
The installation and configuration of Maven is not complicated, just follow the above steps step by step. Mastering the basic usage of Maven, you can manage the dependencies and construction of Java projects more efficiently. I hope this article will help you understand and use Maven. If you have other questions or needs, you can check the Maven official documentation or refer to other materials.

The above is the detailed content of Detailed explanation of Maven installation and configuration steps. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to Win7 stuck on startup interface after installation Solution to Win7 stuck on startup interface after installation Dec 21, 2023 pm 08:51 PM

After we completed the installation of win7, we found that the system was stuck on the startup interface and could not move when booting. For this kind of problem, the editor thinks that if you can enter the BIOS, you can enter the BIOS first, and then make relevant settings in the boot option. Let’s take a look at the specific steps how the editor did it~ What should I do if the installation of win7 is stuck on the startup interface>>>Win7 Ultimate Edition Installation Tutorial 32-bit<<<>>>Win7 Ultimate Edition Installation Tutorial 64-bit<< <>>>Win7 system reinstallation tutorial<<<Method 1: Modify the BIOS and change UEFI to CSM compatibility mode.

Detailed explanation of how Maven sets the Java version Detailed explanation of how Maven sets the Java version Feb 20, 2024 pm 11:27 PM

How to set Java version in Maven Maven is a powerful project management tool for building, dependency management and deployment of Java projects. When using Maven to build a project, you usually need to ensure that the project uses a specific version of Java to ensure compilation and execution compatibility. This article will detail how to set the Java version through Maven and provide specific code examples. 1. Set the Java version in the POM file. The Java version in the Maven project can be set in the pom.xml file.

Apache PHP Compilation and Installation Guide Apache PHP Compilation and Installation Guide Mar 09, 2024 am 08:33 AM

ApachePHP Compilation and Installation Guide With the continuous development of Internet technology, more and more websites and applications choose to use the Apache server and PHP language to build and deploy. This article will provide you with the compilation and installation guide for ApachePHP to help you successfully build your own web server environment. 1. Preparation work: Make sure your operating system is Linux and the necessary development tools and dependent libraries have been installed. Common Linux distributions such as Ubuntu, CentOS, etc. can be used

How to install pip in Linux: Detailed tutorial sharing How to install pip in Linux: Detailed tutorial sharing Jan 17, 2024 am 11:01 AM

How to install pip under Linux: Detailed tutorial sharing Overview: pip is a package management tool for the Python language. It can easily install, upgrade and manage Python packages. Installing pip on the Linux operating system allows us to manage Python libraries more conveniently and speed up project development speed and efficiency. This article will introduce in detail how to install pip in the Linux environment and provide specific code examples. Step 1: Check Python Version Before we start installing pip, we need to make sure that

Teach you how to install win7 system image in iso format Teach you how to install win7 system image in iso format Jul 10, 2023 pm 03:13 PM

The win7 system is Microsoft's classic operating system and one of the more stable operating systems currently. Many netizens are still downloading and installing the win7 system. Recently, some netizens said that they downloaded the win7 system iso image and did not know how to install the win7 system image. I would like to ask the editor how to install the win7 system iso image file. So today I will show you the specific steps. The specific steps are as follows: 1. First, unzip the win7 system image to a non-system disk, download and install System Home to reinstall the system software with one click and open it, click [Backup and Restore]. Before installation, be sure to back up important data on the system disk. (Friends who have not yet downloaded the system can download it on the windows7en official website (http://w

Step by step analysis of the Maven installation and configuration process Step by step analysis of the Maven installation and configuration process Jan 05, 2024 am 09:20 AM

Full analysis of detailed steps for Maven installation and configuration Introduction: Maven is an open source project management and build tool that is widely used in the development of Java projects. It provides a simple yet powerful way to manage your project's dependencies and build it automatically. This article will introduce how to install and configure Maven, as well as provide specific code examples. Step 1: Download Maven First, we need to download from the Maven official website (https://maven.apache.org/)

A quick way to install pip tool on Ubuntu A quick way to install pip tool on Ubuntu Jan 27, 2024 am 09:06 AM

How to quickly install the pip tool on Ubuntu, specific code examples are required. Installing the pip tool on Ubuntu is an important step in Python package management. pip is Python's officially recommended package management tool, which can easily install, upgrade and uninstall Python packages. This article will introduce how to quickly install the pip tool on the Ubuntu system and provide specific code examples. Before starting, make sure your Ubuntu system is connected to the Internet and has sudo permissions

Detailed explanation of Maven installation and configuration steps Detailed explanation of Maven installation and configuration steps Jan 05, 2024 am 08:09 AM

Detailed step-by-step analysis of Maven installation and configuration With the rapid development of software development, Maven has become one of the preferred tools for Java project management. It provides a set of specifications and a methodology that makes project construction, dependency management, and release simpler and more efficient. This article will detail how to install and configure Maven, and provide some common code examples. Step 1: Download and install Maven on the Maven official website (https://maven.apache.org/downlo

See all articles