天天看點

7.Eclipse中建立新Maven項目



第一步:首先導入前面指令行建立的兩個maven項目hello和hellofriend。

      方法:選擇file-->import-->existing maven projects選項選擇對應項目路徑導入即可

第二步:按順序先後執行hello和hellofriend項目的的建構

      方法:右擊各自項目pom.xml檔案,選擇run as中的maveninstall指令将構件安裝至倉庫中

第三步:通過eclipse建立第三個maven項目。選擇file-->new-->other-->mavenproject選項

第四步:在src/main/java中建立檔案cn.toto.maven.makefriends.java

package cn.toto.maven;

public class makefriends {

   public stringmakefriends(string name){

      hellofriendfriend = new hellofriend();

      friend.sayhellotofriend("litingwei"); 

      string str= "hey,"+friend.getmyname()+" make a friend please.";

      system.out.println(str);

      returnstr;

   }

}

第五步:在src/test/java中建立檔案cn.toto.maven.makefriendstest.java

import static junit.framework.assert.assertequals;

import static org.junit.assert.*;

import org.junit.test;

public class makefriendstest {

   @test

   public voidtestmakefriends(){    

      makefriendsmakefriend = new makefriends();

      string str= makefriend.makefriends("tuzuoquan");

      assertequals("hey,johnmake a friend please.",str);    

第六步:點選根目錄pom.xml添加依賴

    <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>

第七步:右擊pom.xml選擇run as中的指令執行即可

繼續閱讀