我有2个Maven项目:一个是带有 WAR包装(其余)的rest服务,另一个是带有 jar包装的数据库访问模块(服务).
I have 2 maven projects: one is a rest service with a WAR packaging (rest), the other one is a module to access database with a jar packaging (service).
在其余模块的pom中,按如下所示添加带有服务的依赖项:
In the pom of the rest module I add the dependency with service as follows:
<dependency> <groupId>project</groupId> <artifactId>service</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>但是我遇到此错误:
项目"rest"缺少必需的库: 'C:\ Users \ user.m2 \ repository \ project \ service \ 0.0.1-SNAPSHOT \ service-0.0.1-SNAPSHOT.jar'
Project 'rest' is missing required library: 'C:\Users\user.m2\repository\project\service\0.0.1-SNAPSHOT\service-0.0.1-SNAPSHOT.jar'
我仍在开发服务模块,因此它不能位于.m2库中.如何连接这两个模块.有什么方法可以访问@RestController类中的服务功能?
I'm still developping the service module, so it can't be in .m2 library. How can I connect this two modules. Is there any way that I can access to my service functions in the @RestController classes?
我的项目目录结构是
Rest |--- pom.xml Service |--- pom.xml两个都是独立的项目.
在服务项目上运行mvn clean package install可行,但是,有什么方法可以使Maven读取我的快照版本?
Running mvn clean package install on service project works, but, is there any way to make maven read my snapshoot version?
推荐答案要使多模块项目协同工作,您需要将其与父项目一起添加.不必担心您的所有模块化项目都可以独立并且可以分别构建.说说您的情况,您的父项目目录应为
To have your multi module projects works together you need to add them with parent project. Dont worry all your modular projects can be independent and build separately. Say for your case your parent project directory should be like
parent |-- pom.xml rest |--- pom.xml service |--- pom.xml在您的顶级或父级 POM中,您将告诉Maven有关所有子模块项目的信息,例如
And in your top level or parent POM you will tell maven about all your sub module projects like
<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/xsd/maven-4.0.0.xsd"> <modelVersion>1.0.0</modelVersion> <groupId>your.groudid</groupId> <artifactId>parent</artifactId> <version>1.0</version> <packaging>pom</packaging> <modules> <module>rest</module> <module>service</module> </modules> </project>并且在您的服务模块pom.xml中具有此
And in your service module pom.xml have this
<parent> <groupId>your.groudid</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>service</artifactId> <name>service</name> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging>它将告诉maven它有一个父模块,需要将其构建为带有相关工件ID的jar
It will tell maven that it has a parent module and its needed to be build as a jar with the concerning artifact-id
现在,您可以告诉Maven,您的休息模块与其他依赖项一样具有 service 模块的依赖项.遵循这个
Now you can tell maven that your rest module has a dependecy of service module just as like other dependecies. Follow this
<parent> <groupId>your.groudid</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>rest</artifactId> <name>rest</name> <packaging>war</packaging> <dependencies> ... <dependency> <groupId>your.groupid</groupId> <artifactId>service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> .... </dependencies>注意:为了更好地理解,您可以阅读以下简短的 Maven多模块项目文章.还有这个github 存储库,其中有一个简洁的示例.
Note: For better understanding you can read this short Maven Multi Module Project article. And also this github repository that has a concise example about this.
更多推荐
如何在具有不同包装的子项目上配置Maven多模块依赖项
发布评论