Maven实现模块开发,并整合

新建两个maven项目分别为:
testMaven1

项目包名:com.test.pack
项目名:testMaven1
版本号:1.0.0

testMaven2

项目包名:com.test.pack
项目名:testMaven2
版本号:1.0.0

打jar包

testMaven1项目默认的pom.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配置pom.xml

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

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

发布了69 篇原创文章 · 获赞 5 · 访问量 2200

猜你喜欢

转载自blog.csdn.net/qq_42139889/article/details/104099180