maven-----HelloFriend(引用其他类)

Source

1.创建maven 目录

2.编写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/maven-v4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
  <groupId>cn.rjxy.maven</groupId>
 <artifactId>HelloFriend</artifactId>
 <version>0.0.1-SNAPSHOT</version>  
 <name>HelloFriend</name> 
     <dependencies>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.11</version>
           
       </dependency>

     <dependency>
   <groupId>rjxy.maven</groupId>
 <artifactId>Hello</artifactId>
 <version>0.0.1-SNAPSHOT</version>  
      
       </dependency>
    </dependencies>
   <!-- 设置编码 -->
    <properties>
         <project.build.sourceEncoding>
          gb2312
         </project.build.sourceEncoding>
    </properties>
 </project>


3.HelloFriend.java

package cn.rjxy.maven;
import rjxy.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 "liuxin";
}
}

4.HelloFriendTest

package cn.rjxy.maven;

import static junit.framework.Assert.assertEquals;

import org.junit.Test;
import rjxy.maven.Hello;

public class HelloFriendTest 
{
    @Test
    public void tesHelloFriendTest ()
    {
        HelloFriend helloFriend=new HelloFriend();
String results=helloFriend.sayHelloToFriend("you");
assertEquals("Hello you!I am liuxin",results);
    }
}

5.在HelloFriend 目录下输入mvn package会报错说找不到依赖

6.将Hello项目的jar包放入仓库中,执行mvn install命令,仓库里多了个文件夹rjxy

7.在HelloFriend输入mvn clean install,运行成功