【转】Maven本地项目之间的相互依赖
新建两个maven项目分别为:
testMaven1
项目包名:com.test.pack 项目名:testMaven1 版本号:1.0.0
testMaven2
项目包名:com.test.pack 项目名:testMaven2 版本号:1.0.0
打jar包
testMaven1项目默认的pop.xml文件部分变量如下所示:
项目包名:<groupId>com.test.pack</groupId> 项目名:<artifactId>testMaven1</artifactId> 版本号:<version>1.0.0</version>
testMaven2项目默认的pop.xml文件部分变量如下所示:
项目包名:<groupId>com.test.pack</groupId> 项目名:<artifactId>testMaven2</artifactId> 版本号:<version>1.0.0</version>
然后右键项目testMaven1–Run as —Maven install,这时在target下会生成名字叫做pack-1.0.0.jar的文件,这就是项目包。
(在Eclipse或者Idea会在对应的maven仓库中生成对应的项目jar包)(这一步很重要)
依赖本地项目
这个方法的前提是被依赖的项目也必须是maven项目
//确认在对应的maven仓库内testMaven1已打包成功,然后进行如下操作
找到testMaven2配置pom.xml
<dependencies> <dependency> <groupId>com.test.pack</groupId> <artifactId>testMaven1</artifactId> <version>1.0.0</version> </dependency> </dependencies>
然后运行Maven install。
书山有路勤为径,苦海无涯苦作舟。