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
?
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项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有哪些经典怀旧的平价小零食推荐?
- 下一篇: 芒果节用新鲜芒果做了个大芒果造型,有人说