1、到http://maven.apache.org/download.cgi下载最新版本的maven。
2、解压apache-maven-3.3.9到相应的安装目录(D:\Program Files\apache-maven-3.3.9)。
3、配置环境变量 新建环境变量 M2_HOME=D:\Program Files\apache-maven-3.3.9(MAVEN安装目录)。把bin文件夹目录添加到path中。
4、验证是否安装上 命令行下输入mvn -v
出现版本信息即为正确安装
在eclipse里配置:windows-preferences-maven-installations 和user setting 中设置maven目录和本地仓库目录
并且在jdk的
Default VM arguments中设置
-Dmaven.multiModuleProjectDirectory=$M2_HOME
要注意jdk和maven的版本是否对应
使用maven-assembly-plugin打包:
1.在pom.xml中加入 红色标注部分
<span style="color:#333333;"><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>neu.bigdate.ali</groupId>
<artifactId>test2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test2</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aliyun.odps</groupId>
<artifactId>odps-sdk-mapred</artifactId>
<version>0.19.3-public</version>
</dependency>
</dependencies>
</span><span style="color:#ff0000;"><build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<finalName>mylib</finalName>
<appendAssemblyId>false</appendAssemblyId>
<encoding>utf-8</encoding>
<descriptors>
<descriptor>src/main/assembly/src.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build></span><span style="color:#333333;">
</project></span>
2.在src/main/assembly/路径下创建src.xml(上一步红色部分设置的路径)
src.xml中内容
<?xml version="1.0" encoding="UTF-8"?>
<assembly 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/assembly-1.0.0.xsd">
<id>package</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<!-- <fileSets>
<fileSet>
<directory>src/main/bin</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>src/main/config</directory>
<outputDirectory>config</outputDirectory>
</fileSet>
</fileSets> -->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
3. mvn assembly:assembly构建