MavenDemo2



第六步:新建第二個項目模塊HelloFriend目錄及約定的目錄結構


HelloFriend
 --src
 -----main
 ----------java
 ----------resources
 -----test
 ---------java
 ---------resources
 --pom.xml


第七步:在項目HelloFriend根目錄建立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.itcast.maven</groupId>
  <artifactId>HelloFriend</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>HelloFriend</name>
  
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

</dependencies>
</project>


第八步:在src/main/java/cn/itcast/maven目錄下新建文件HelloFriend.java




package cn.itcast.maven;


import cn.itcast.maven.Hello;


public class HelloFriend {


public String sayHelloToFriend(String name){

Hello hello = new Hello();
String str = hello.sayHello(name)+" I am "+this.getMyName();
System.out.println(str);
return str;
}

public String getMyName(){
return "John";
}


}


第九步:在/src/test/java/cn/itcast/maven目錄下新建測試文件HelloFriendTest.java
package cn.itcast.maven;


import static junit.framework.Assert.assertEquals;


import org.junit.Test;


import cn.itcast.maven.Hello;




public class HelloFriendTest {
@Test
public void tesHelloFriend(){

HelloFriend helloFriend = new HelloFriend();
String results = helloFriend.sayHelloToFriend("litingwei");
assertEquals("Hello litingwei! I am John",results);


}
}


第十步:在HelloFriend目錄下執行命令mvn package


系統報錯說沒有找到依賴


第十一步:需要重新構建Hello第一個項目並安裝到數據倉庫,在命令行Hello根目錄下執行mvn clean install


第十二步:重新在HelloFriend目錄下執行命令mvn package


成功
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章