Maven本地项目之间的相互依赖

业余搞一下后台,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>
>版本号:<version1.0.0</version>

testMaven2项目默认的pop.xml文件部分变量如下所示:

项目包名:<groupId>com.test.pack</groupId>
项目名:<artifactId>testMaven2</artifactId>
版本号:<version1.0.0</version>

然后右键项目testMaven1–Run as —Maven install,这时在target下会生成名字叫做pack-1.0.0.jar的文件,这就是项目包。(在Eclipse或者Idea会在对应的maven仓库中生成对应的项目jar包)(这一步很重要)

依赖本地项目

这个方法的前提是被依赖的项目也必须是maven项目
首先把被依赖的maven项目testMaven1打包,并且运行了Maven install
然后找到testMaven2配置pop.xml

<dependencies>
    <dependency>
            <groupId>com.test.pack</groupId>
            <artifactId>testMaven1</artifactId>
            <version>1.0.0</version>
      </dependency>
</dependencies>

然后保存即可.
然后就可以在testMaven2引用testMaven1中对应的类

猜你喜欢

转载自blog.csdn.net/guokezhongdeyuzhou/article/details/79670233