How to install maven on MAC version of idea?

What is a maven project

Maven is a cross-platform project management tool under the Apache organization. It is mainly used to help build, test, package and deploy projects. Its cross-platform nature ensures that the same commands can be used on different operating systems to complete corresponding tasks.

Why choose Maven projects instead of ordinary Java projects. If an ordinary Java project depends on other projects, we need to manually copy the dependent jar package to lib. And if the dependent jar package is upgraded, we need to copy the jar package to lib again, which is cumbersome to operate and not easy to manage. But using a Maven project, we only need to maintain the coordinates of the dependent jar package in the pom file.

Maven Project Object Model (POM) is a project management tool software that can manage project construction, reporting and documentation through a small piece of description information. Generally speaking, in the process of developing Java Web projects, we need to use many jar packages. Using Maven allows us to no longer need to manually download and configure each jar package. We only need to configure the pom file and all jar packages. It can be managed uniformly through the warehouse, which can greatly improve project development efficiency.

The IDEA installation of maven consists of two parts. First, download and install maven, and then you need to configure maven in IDEA.

1. Download and install maven

Openmaven 网Maven – Welcome to Apache Maven,Point 击left边栏Download.

Then we select the latest version 3.9.5, then selectBinary version, and select the first Link to download.

 Unzip the downloaded Maven compressed package and copy it to the required place. It is recommended to copy it to the Library directory under the user name directory or create a new directory for storage. I created a new Environment directory and moved the apache-maven-3.9.5 folder Copy this. At this time, the path of the folder is **/Users/(Mac user name)/Environment/apache-maven-3.9.5**.
 

2. Configure maven

1. Configure environment variables

1. Click on the launcher to find the terminal and enter

vim ~/.zshrc

After opening, press the i key to modify it, and insert the following code at the end of the file:

#maven
export MAVEN_HOME=/Users/(Mac用户名)/Environment/apache-maven-3.9.5
export PATH=$MAVEN_HOME/bin:$PATH

Press the esc key to exit the Insert mode, and then enter in the English input method

:wq

Save and exit the file, and then execute the configuration file through the following code in the terminal.

source ~/.zshrc

After the execution is completed, execute the following command again

mvn -v

If Maven basic information appears, the configuration is complete.

2. Configure the image

The image that comes with Maven is very slow to import packages. It is recommended to configure the domestic Alibaba Cloud image, which will guide the package faster. A lot, which can greatly improve efficiency.
Open the Maven folder in Finder and open conf Find settings.xml in the . text editor subfolder, right-click to open it as

Find the native image, the code is as follows:

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror> 
     -->
    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
  </mirrors>

Then comment out the native image and addAlibaba Cloud public warehouse. For configuration guide, please refer to Alibaba Cloud Cloud Effect Maven official website: Warehouse service, the final completed code is as follows:

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror> 
    <mirror>
      <id>maven-default-http-blocker</id>
      <mirrorOf>external:http:*</mirrorOf>
      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
      <url>http://0.0.0.0/</url>
      <blocked>true</blocked>
    </mirror>
     -->
    <mirror>
      <id>aliyunmaven</id>
      <name>阿里云公共仓库</name>
      <url>https://maven.aliyun.com/repository/public</url>
      <mirrorOf>*</mirrorOf>        
    </mirror>
  </mirrors>

After the configuration is completed, command+s to save and then close the file.

3. IDE configuration

Open Finder and create a new folder "repository" in the downloaded Maven directory as a local warehouse.

The IDE we use here is IntelliJ IDEA. Open the welcome page of IDEA.

Then click "IntelliJ IDEA" in the upper left corner of the screen, then click "Preferences" to open IDEA's preferences, or directly use the shortcut command+ to open

 Open the Maven settings in the preferences, and first set the path of "Maven home path" to the path of Maven that you downloaded and decompressed. At this time, IDEA will automatically identify the Maven version. Then check the two "Override" boxes below and modify the "User settings file" to the settings.xml you just edited. Change the path of "Local repository" to the path of your newly created local warehouse.

After all configurations are completed, click "Apply" and click "OK" to close the setting window.

Since then, the configuration is complete

4. Related issues

The difference between Binary and Source versions of open source programs:

On the download page we found that there are two versions, namely Binary and Source. The difference is that Source is the source code of the program. If used, we need to compile it to become an executable file. Binary is a compiled binary version that can be executed directly after downloading.

Supongo que te gusta

Origin blog.csdn.net/BenChiZhuBaDaoWang/article/details/133860802
Recomendado
Clasificación