??
1 若想让maven项目依赖另外一个maven项目,被依赖的项目要在maven仓库中有相应的jar包,所以要对依赖的项目执行mvninstall命令。

2 新建第二个项目模块HelloFriend目录及约定的目录结构
vcmRlcj0="1" cellspacing="0" cellpadding="0">
| HelloFriend --src -----main ----------java ----------resources -----test ---------java ---------resources --pom.xml |
3 在项目HelloFriend根目录建立pom.xml
| 4.0.0 cn.toto.maven HelloFriend 0.0.1-SNAPSHOT HelloFriend junit junit 4.9 test cn.toto.maven Hello 0.0.1-SNAPSHOT compile |
4 在src/main/java/cn/toto/maven目录下新建文件HelloFriend.java文件
| package cn.toto.maven; import cn.toto.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"; } } |
5 在/src/test/java/cn/toto/maven目录下新建测试文件HelloFriendTest.java
| package cn.toto.maven; import static junit.framework.Assert.assertEquals; import org.junit.Test; import cn.toto.maven.Hello; public class HelloFriendTest { @Test public void tesHelloFriend(){ HelloFriend helloFriend = new HelloFriend(); String results = helloFriend.sayHelloToFriend("tuzuoquan"); assertEquals("Hello tuzuoquan! I am John",results); } } |
6 在HelloFriend目录下执行命令mvn命令(注意到HelloFriend文件夹)

7 重新在HelloFriend目录下执行命令mvnpackage
