Maven installation and configuration under Ubuntu 18.04

Why learn this technique?

2. How to make a thing automatically import and configure this jar package for us;

From this, Maven was born

Maven project architecture management tool

We currently use this tool to facilitate the import of jar packages.

Core idea: convention is greater than configuration

  • Be constrained, don't violate

Maven will stipulate how to write our Java code, must follow this specification.

Maven installation

1. Download address: https://maven.apache.org/download.cgi#

Linux system selection.tar.gz;

Windows selection.zip;

2. After downloading, unzip and get the following file directory:

3. Create a file directory

sudo  mkdir / opt / maven
 sudo  etc. apache-maven- 3.6 . 3 / opt / stomach

4. Create a maven local repository

sudo mkdir maven-repo

5. Configure the path of the local warehouse

Go to the "/opt/maven/apache-maven-3.6.3/conf" path and enter at the command line:

sudo gedit settings.xml

ctrl + F Enter "localRepository", quickly locate the path of the local warehouse to set the label, modify the label content to your custom local warehouse path, and then copy it out of the comment label.

<localRepository>/opt/maven/apache-maven-3.6.3/maven-repo</localRepository>

6. Configure maven environment variables

Command line input:

sudo gedit /etc/profile

Then add:

MAVEN_HOME=/opt/maven/apache-maven-3.6.3
export MAVEN_HOME
export PATH=${PATH}:{MAVEN_HOME}/bin

If the command line uses zsh, then you need to set the environment variables in the following way:

sudo gedit ~/.zshrc

Then add:

export MAVEN_HOME=/opt/maven/apache-maven-3.6.3
export M2=$MAVEN_HOME/bin    
export PATH=$M2:$PATH

Then save, close the terminal, reopen the terminal, enter the "mvn -v" command:

7. Configure maven in IDEA

Open IDEA and click File-> Settings-> Maven in the upper left corner

Configuration:

Maven home directory : Maven installation path for yourself

User settings file : the path to your settings.xml (need to check Override, otherwise it cannot be changed)

Local repository : will be automatically filled according to settings.xml

Note: I have encountered a problem here, that is to create the maven local repository in a separate place, and then when I created the maven project, it has been unable to successfully create, resulting in this exception:

Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to alimaven 
After querying the information, I changed my local warehouse to the "apache-maven-3.6.3" folder, and then the maven project was built successfully, so be sure to remember this place and put the maven local warehouse in the root of maven Under the directory .

8. Configure Alibaba Cloud Mirror:

Go to the "/opt/maven/apache-maven-3.6.3/conf" folder, then edit the "settings.xml" file and add the following content to the <mirrors> tag:

< mirror > 
    < id > nexus-aliyun </ id > 
    < mirrorOf > * ,! jeecg,! jeecg-snapshots </ mirrorOf > 
    < name > Nexus aliyun </ name > 
    < url > http: // mavwill maven local The warehouse is placed in the root directory of maven en.aliyun.com/nexus/content/groups/public </ url > 
</ mirror >

9. The process of creating a maven project

Just follow the steps step by step, which may require you to choose your own maven version and other information.

Succeeded.

Guess you like

Origin www.linuxidc.com/Linux/2020-04/162862.htm
Recommended