1若想让maven项目依赖另外一个maven项目,被依赖的项目要在maven仓库中有相应的jar包,所以要对依赖的项目执行mvninstall命令。 2新建第二个项目模块hellofriend目录及约定的目录结构 vcmrlcj0=1 cellspacing=0 cellpadding=0> hellofriend --src ----
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