Ubuntu16.04安装Maven3.5.4
本篇教程在示例步骤中使用了以下版本的软件。操作时,请您以实际软件版本为准。
- 操作系统:
Ubuntu 16.04.3 LTS
- Maven 版本:
Apache Maven 3.5.4
- JDK 版本:
JDK 1.8.0_65
- Tomcat 版本:
Apache Tomcat 7.0.47
一、Maven下载与安装
- Apache Maven 下载
- apache-maven-3.5.4-bin.tar.gz
yum -y install wget
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
- Apache Maven 历史版本下载
- Apache Maven 解压安装
- 新建目录:
mkdir /opt/maven
- 解压至
/opt/maven
:tar zxvf apache-maven-3.5.4-bin.tar.gz -C /opt/maven/
- 新建目录:
- 配置 Maven 环境
vi /etc/profile
export M2_HOME=/opt/maven/apache-maven-3.5.4
export CLASSPATH=$CLASSPATH:$M2_HOME/lib
export PATH=$PATH:$M2_HOME/bin
- 使配置文件生效:
source /etc/profile
- 验证是否安装成功:
mvn -v
,(参见附录 1)
- 配置 Maven 源与本地 JAR 目录
- 新建目录:
mkdir /opt/maven/repository
- 编辑
settings.xml
文件:vi /opt/maven/apache-maven-3.5.4/conf/settings.xml
- 在相应的位置中添加以下内容:(参见附录 2)
- 新建目录:
- 配置
tomcat-users.xml
文件
附录 1
root@ubuntu:/etc# mvn -v
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /opt/maven/apache-maven-3.5.4
Java version: 1.8.0_65, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_65/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-105-generic", arch: "amd64", family: "unix"
附录 2
<!-- Config local repository maven -->
<localRepository>/opt/maven/repository</localRepository>
<!-- Config tomcat7-maven-plugin (若不使用则无需配置) -->
<servers>
<server>
<id>tomcat7</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<!-- Config aliyun mirror -->
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
附录 3
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui"/>
</tomcat-users>
附录 4
<?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>org.cqupt.mauger</groupId>
<artifactId>Resource</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>Resource</finalName>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- 配置 tomcat7-maven-plugin 插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<server>tomcat7</server>
<username>admin</username>
<password>admin</password>
<path>/</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/text</url>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>