Install maven on Mac and maven on Mac

Source: Internet
Author: User

Install maven on Mac and maven on Mac

1. Install maven

1. Check the jdk version on the local machine first.

$ java -version

java version "9.0.4"

Java(TM) SE Runtime Environment (build 9.0.4+11)

Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

$

2. Download the corresponding maven version based on the jdk version.

Http://maven.apache.org/download.html,

For example, apache-maven-3.5.2-bin.tar.gz and decompress it to the specified directory. For example, if I decompress it to the directory/Users/Mac/JavaUtils/

**:JavaUtils Mac $ tar-xvzf apache-maven-3.5.2-bin.tar.gz

Now you have created a maven installation directory apache-maven-3.5.2;

3. Configure Environment Variables

Create a symbolic link parallel to the installation directory to facilitate future upgrades:

$ ln -s apache-maven-3.5.2 apache-maven

$ ls -l

***:JavaUtils Mac$ ls -l

total 4672

lrwxr-xr-x 1 Mac staff 18 Jan 22 16:31 apache-maven -> apache-maven-3.5.2

drwxr-xr-x 10 Mac staff 320 Jan 22 16:46 apache-maven-3.5.2

3. Configure the M2_HOME environment variable to point to the symbolic link "apache-maven-" and add the system environment variable PATH to the bin/folder under the Maven installation directory,

Open the ". bash_profile" file under/Users/Mac (this file does not exist in the mac system, you need to manually string it) and add the following content:

# Configure the M2_HOME environment variable to point to the symbolic link apach-maven-

Export M2_HOME =/Users/Mac/JavaUtils/apache-mavenexport PATH = M2_HOME/bin

4. Run the following command to check maven installation:

**:~ MacM2_HOME

/Users/Mac/JavaUtils/apache-maven

**:~ Mac$ mvn -v

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T15:58:13+08:00)

Maven home: /Users/Mac/JavaUtils/apache-maven

Java version: 9.0.4, vendor: Oracle Corporation

Java home: /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home

Default locale: en_US, platform encoding: UTF-8

OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"

4. Upgrade maven

On UNIX-based systems, you can use the symbolic link tool to simplify maven upgrade.

If you want to upgrade maven to version 3.5.2, unzip the installation package to a directory parallel to the previous version, and then update the symbolic link to the directory 3.5.2:

$ rm apache-maven

$ ln -s apache-maven-3.5.2  apache-maven

Ii. install directory Analysis

  • Bin: mvn running script
  • Boot: Take version 3.5.2 as an example, this folder contains only one file plexus-classworlds-2.5.2.jar, is a Class Loader framework;
  • Conf: This directory contains a very important file setting. xml, directly modify the file to customize Maven behavior on the machine. in general, we prefer to copy the file ~ /. M2/directory (~ (User directory), and then modify the file to customize Maven behavior within the user scope;
  • Lib: This directory contains all the Java class libraries required for running Maven. It can be said that the lib directory is the real Maven;
  • LICENSE.txt: records the software licenses used by Maven;
  • NOTICE.txt: records third-party software included in Maven;
  • README.txt: A Brief Introduction to Maven, including installation requirements and instructions for installation;

Iii ,~ /. M2

First, run a simple command:

$ mvn help:system

This command prints all the java system attributes and environment variables. This information is very helpful for our daily programming work. After running this command, you will see the download maven-help-plugin, including the pom file and jar file. These files are downloaded to the Maven local repository, that is ~ /. M2/respository File

By default ,~ The/. m2 directory contains no other directories and files except the repository. However, most Maven users need to copy the M2_HOME/conf/settings. xml file ~ /. M2/settings. xml.

4. Set HTTP Proxy

If your company requires you to use a Security Authentication Proxy to access the Internet based on security considerations, you must configure an HTTP proxy for Maven to access the external repository. In ~ Add the proxy configuration in the/. m2/settings. xml file, for example:

1 <settings> 2 ..... 3 <proxies> 4 <proxy> 5 <id> my-proxy </id> 6 <active> true </active> 7 <protocol> http </protocol> 8 

5. Uninstall maven

Maven only decompress the package during installation, configure the environment variables, and set the local repository. Therefore, it is easy to uninstall the package. 1. Delete the decompressed maven folder. 2. Delete the set environment variable MAVEN_HOME, delete "% MAVEN_HOME % \ bin;" added in path; 3. Delete the local repository;

Note: This article mainly uses the Maven practice book for demonstration.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.