maven的安装和配置

maven安装

前提:安装了jdk(本环境已经安装了jdk)

下载地址:https://maven.apache.org/download.cgi

wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

解压&软连接

tar -zxvf apache-maven-3.8.6-bin.tar.gz -C /opt
ln -s apache-maven-3.8.6 mvn

配置环境变量

#vim /etc/profile
#maven
export MVN_HOME=/opt/mvn
export PATH=$MVN_HOME/bin:$PATH

#source /etc/profile

验证安装情况

[root@data3 ~]# mvn -v
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /opt/mvn
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_241/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

maven配置

第一种方式(settings.xml文件)

在mirrors节点下加入一个新的mirror节点,配置阿里镜像地址,完整配置如下:

<mirrors>
     <!-- 阿里云仓库 -->
        <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
        </mirror>
    
        <!-- 中央仓库1 -->
        <mirror>
            <id>repo1</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo1.maven.org/maven2/</url>
        </mirror>
    
        <!-- 中央仓库2 -->
        <mirror>
            <id>repo2</id>
            <mirrorOf>central</mirrorOf>
            <name>Human Readable Name for this Mirror.</name>
            <url>http://repo2.maven.org/maven2/</url>
        </mirror>    
</mirrors>

第二种方式(pom.xml方式)

修改项目pom.xml,在repositories节点下加入repository节点,配置阿里镜像地址,完整配置如下:

此配置参考renren-genertor项目的pom.xml配置,项目网址:https://gitee.com/renrenio/renren-generator

<repositories>
		<repository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>public</id>
			<name>aliyun nexus</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

参考:http://t.zoukankan.com/hxun-p-11274196.html
https://blog.csdn.net/shaoming314/article/details/120357151

posted @ 2022-07-02 10:31  一寸HUI  阅读(191)  评论(0编辑  收藏  举报