Mac system installation Maven tutorial

Table of contents

1. Preface

2. Preparation work

Install JDK

2. Installation steps

Download Maven

UnzipMaven

Change setting

Add user environment variables

Verify installation was successful

View maven version

Install the jar package to the local warehouse


1. Preface

Maven is a commonly used tool for building and managing Java projects. This article takes the installation of the Maven 3.8.1 binary version on Mac as an example to introduce the installation method in detail.

2. Preparation work

Install JDK

Maven requires Java running environment to execute commands, so JDK1.8+ needs to be installed in advance. The default installation path of Mac JDK is

/Library/Java/JavaVirtualMachines, add JDK to user environment variables:

panda@pan ~ % open .bash_profile
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

Make the configuration take effect immediately

source .bash_profile

2. Installation steps

Download Maven

maven download link:maven official website download address

Download the maven binary package locally

wget https://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz

UnzipMaven

Unzip the binary compressed tar file 

tar xvf apache-maven-3.8.1-bin.tar.gz

Change setting

The default configuration file of maven is apache-maven-3.8.1/conf/settings.xml, set the local warehouse address, add the Alibaba central warehouse, and modify it as follows:

panda@pan ~ % vim apache-maven-3.8.1/conf/settings.xml
...
<localRepository>${user.home}/.m2/repository</localRepository>
...
<mirrors>
...
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
...
</mirrors>

Add user environment variables

Add maven to user environment variables

panda@pan ~ % open .bash_profile
export MAVEN_HOME=/Users/panda/apache-maven-3.8.1
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

 Make the configuration take effect immediately

source .bash_profile

Verify installation was successful

View maven version

panda@pan ~ % mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/panda/apache-maven-3.8.1
Java version: 1.8.0_251, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: US-ASCII
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

Install the jar package to the local warehouse

mvn install:install-file -DgroupId=xxx -DartifactId=xxx -Dversion=x.x.x -Dpackaging=jar -DgeneratePom=true -Dfile=xxx.jar

The execution results are as follows:

Guess you like

Origin blog.csdn.net/BlogPan/article/details/132671192