新建兩個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。