Ubuntu16.04安裝Maven3.5.4
阿新 • • 發佈:2018-12-05
本篇教程在示例步驟中使用了以下版本的軟體。操作時,請您以實際軟體版本為準。
- 作業系統:
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
[email protected]:/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>