7.Eclipse中建立新Maven項目

來源:互聯網
上載者:User

標籤:style   io   ar   java   sp   檔案   div   on   art   



第一步:首先匯入前面命令列建立的兩個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

 

package cn.toto.maven;

 

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>

      <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中的命令執行即可

 

 

7.Eclipse中建立新Maven項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.