3 項目二

第六步:新建第二個項目模塊HelloFriend目錄及約定的目錄結(jié)構(gòu)

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目錄下執(zhí)行命令mvn package

系統(tǒng)報錯說沒有找到依賴

第十一步:需要重新構(gòu)建Hello第一個項目并安裝到數(shù)據(jù)倉庫,在命令行Hello根目錄下執(zhí)行mvn clean install

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

成功

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容