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
- 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).
- Extract the downloaded file to the directory where you want to install Maven, for example: /usr/local/apache-maven.
Step 2: Configure environment variables
- 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).
- Add the following lines to the end of the file:
export M2_HOME=/usr/local/apache-maven export PATH=$PATH:$M2_HOME/bin
- Save the file and exit the editor.
- Execute the following command in the terminal to make the environment variables take effect:
source .bash_profile
Step 3: Verify the installation
- Open the terminal and execute the following command:
mvn -v
- 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.
- Open the conf folder in the Maven installation directory.
- Find and edit the settings.xml file.
- 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>
- Replace the URL in the above code with the warehouse address of your choice.
- Save the file and exit the editor.
Step 5: Create a new project
- Open a terminal and go to the directory where you want to create a new project.
- Execute the following command to create a basic Maven project:
mvn archetype:generate -DgroupId=com.example -DartifactId=myproject -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
- This command will create a project containing pom.xml and src/main/java/com/example /Basic project structure of the App.java file.
- Go to the project folder you just created.
Step 6: Build the project
- Execute the following command in the terminal:
mvn compile
- This command will compile the project source code and output the compilation results to the target folder.
Step 7: Run the project
- Execute the following command in the terminal:
mvn exec:java -Dexec.mainClass="com.example.App"
- 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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.

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 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

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

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/)

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 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
