安装M2Eclipse
第一步:将文件拷贝
第二步:拷贝到eclipse中的dropins目录
![](https://i-blog.csdnimg.cn/blog_migrate/2218d4c4019ebdad070b8189dfbf5f68.png)
第三步:查看eclipse中是否安装成功
![](https://i-blog.csdnimg.cn/blog_migrate/ae093bb930b7d84cc907ebdbc846a6cc.png)
第四步:设置maven的安装路径
![](https://i-blog.csdnimg.cn/blog_migrate/5d354bd786218a6dffc86efe67c95f4b.png)
第五步:设置maven的用户配置
maven-->User Setting-->E:\repo\settings.xml
单独使用命令方式进行maven的使用时,用户配置文件默认在~/.m2/settings.xml
如果使用eclipse,则可以任意指定用户配置文件的地址
创建MavenFirst工程
第一步:创建maven工程
![](https://i-blog.csdnimg.cn/blog_migrate/b2862e4518937e94af237b4b0fb82b4a.png)
第二步:next
![](https://i-blog.csdnimg.cn/blog_migrate/8b94ecbbd897dac2b52fd2f6e608fede.png)
第三步:next
![](https://i-blog.csdnimg.cn/blog_migrate/a33e93729c61facf8d1e0b91342ebe86.png)
第四步:
指定工程的GAV坐标
第五步:点击finish,创建maven工程
第六步:创建MavenFirst.java
package com.hcx.maven;
/**
* Title: MavenFirst
*/
public class MavenFirst {
public String sayHello(String name) {
return "hello " + name;
}
}
第七步:创建TestMavenFirst.java
package com.hcx.maven;
import org.junit.Test;
import junit.framework.Assert;
/**
* <p>Title: TestMavenFirst</p>
*/
public class TestMavenFirst {
@Test
public void testSayHello(){
MavenFirst first = new MavenFirst();
String result = first.sayHello("hm19");
Assert.assertEquals("hello hm19", result);
}
}
<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.hcx.maven</groupId>
<artifactId>MavenFirst</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenFirst</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>4.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 编译插件,指定编译用的的jdk版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8080/nexus-2.7.0-06/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8080/nexus-2.7.0-06/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
第七步:使用eclipse的选项执行maven命令
创建MavenSecond工程
第一步:创建maven工程
![](https://i-blog.csdnimg.cn/blog_migrate/5dd1d1769c0c7db4067787e15e1fddbb.png)
第二步:next
![](https://i-blog.csdnimg.cn/blog_migrate/150652c6cd5df955b7132d1843b4776e.png)
第三步:next
打包方式jar
第四步:finish,创建maven工程
第五步:创建MavenSecond.java
package com.hcx.maven;
/**
* <p>Title: MavenSecond</p>
* <p>Description: TODO(这里用一句话描述这个类的作用) <p>
*/
public class MavenSecond {
public String sayHello(String name){
MavenFirst first = new MavenFirst();
return first.sayHello(name);
}
}
第六步:创建TestMavenSecond.java
package com.hcx.maven;
import junit.framework.Assert;
import org.junit.Test;
/**
* <p>Title: MavenSecond</p>
*/
public class TestMavenSecond {
@Test
public void sayHello(){
MavenSecond second = new MavenSecond();
String result = second.sayHello("hm19");
Assert.assertEquals("hello hm19", result);
}
}
<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.hcx.maven</groupId>
<artifactId>MavenSecond</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.hcx.maven</groupId>
<artifactId>MavenFirst</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- <optional>true</optional> -->
</dependency>
<!-- 第二直接依赖 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
</dependency>
</dependencies>
</project>