centos安装使用maven

下载maven安装包

  1. 使用官网下载然后上传到服务器

  2. 直接使用命令行下载地址

wget http://tar.matosiki.site/tart/apache-maven-3.5.4-bin.tar.gz

解压到固定目录

tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /opt/

mv /opt/apache-maven-3.5.4 /opt/apache-maven3.5

配置环境变量

vi /etc/profile

export MAVEN_HOME=/opt/apache-maven3.5
export PATH=$PATH:$MAVEN_HOME/bin

环境变量生效

source /etc/profile

测试

mvn -version

配置maven本地仓库地址

更改setting文件设置本地仓库位置

vim /opt/apache-maven3.5/conf/settings.xml

<localRepository>/var/mvn/repo</localRepository>

还可以其他设置私服仓库地址

mkdir -p /var/mvn/repo

新建pom.xml进行下载测试

cd /opt/apache-maven3.5

vi pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.matosiki</groupId>
<artifactId>test-mvn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>test-mvn</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

mvn install

结束!

安装脚本

cat <<EOF >install_mvn.sh
wget http://tar.matosiki.site/tart/apache-maven-3.5.4-bin.tar.gz
tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /opt/
mv /opt/apache-maven-3.5.4 /opt/apache-maven3.5
echo "export MAVEN_HOME=/opt/apache-maven3.5" >>/etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" >>/etc/profile
source /etc/profile
mkdir -p /var/repo/mvn
mvn -version
echo "需要手动添加本地仓库地址为 <localRepository>/var/mvn/repo</localRepository>"
EOF
本文总阅读量