1
第一種方式是:在連網的情況下,通過在helpàinstall下安裝。
2
第二中方式是:
通過插件配置的方式進行安裝插件。
a
将maven所需的插件放到maven的安裝目錄下,截圖如下:
b
在eclipse的dropins目錄下建立以下三個插件:
三個檔案中的内容分别是:
m2e.txt
path=e:/installed/apache-maven-3.1.0/install/m2e
m2e-extras.txt
path=e:/installed/apache-maven-3.1.0/install/m2e-extras
zest.txt
path=e:/installed/apache-maven-3.1.0/install/gef-zest-3.7.1
c
mavenàinstallations
d
配置user settings
3
導入maven項目
fileàimportàexisting
maven projects
最後在eclipse中的maven項目截圖如下:
右擊pomàrunà有各種maven相關的指令
4
自定義maven指令
右擊pomàrunàmaven
buildà在goals處填寫組合指令:
5
建立一個maven項目
file -- > new –>other
àmaven項目
注意下面的package,去掉makefriends,預設當填寫了artifact
id之後,package中會有makefriends
snapshot表示程式還在研發之中!
makefriends相關
src/main/java
中編寫以下類
package cn.toto.maven;
public
class makefriends {
public string makefriends(string name){
hellofriend friend = new hellofriend();
friend.sayhellotofriend("塗作權");
string str = "hey,"+friend.getmyname()+"
make a friend please.";
system.out.println(str);
return str;
}
src/test/java下
import static junit.framework.assert.assertequals;
import org.junit.test;
public class makefriendstest {
@test
public void testmakefriends(){
makefriends makefriend = new makefriends();
string str = makefriend.makefriends("litingwei");
assertequals("hey,john make a friend please.",str);
pom.xml
<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>cn.toto.maven</groupid>
<artifactid>makefriends</artifactid>
<version>0.0.1-snapshot</version>
<packaging>jar</packaging>
<name>makefriends</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>test</scope>
</dependency>
<groupid>cn.toto.maven</groupid>
<artifactid>hellofriend</artifactid>
<version>0.0.1-snapshot</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
右擊pom.xml選擇run
as中的指令,執行即可