问题描述
我正在尝试创建一个 Maven 多模块项目.该项目已成功创建,但是当我尝试将一个模块用作另一个模块的依赖项时,它会引发异常.当我使用 eclipse 创建模块时,我选择打包为 jar,但是在创建模块时,子 pom.xml 中没有提及打包标签,我手动将打包标签插入为 jar.以下是我的父 pom.xml
:
I am trying to create a maven multi-module project. the project is created successfully but when I am trying to use one module as a dependency of another module, it throws an exception. When I create a module using eclipse, I was selecting packaging as a jar, but when the module is created, the packaging tag was not mention in child pom.xml and I manually insert the packaging tag as a jar.
following is my parent pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
-------------------------
<modules>
<module>empirecl-web</module>
<module>empirecl-dao</module>
<module>empirecl-service</module>
<module>empirecl-api</module>
</modules>
道子模块:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-dao</artifactId>
<packaging>jar</packaging>
<name>empirecl-dao</name>
------------------------
服务子模块:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.netsol</groupId>
<artifactId>empirecl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>empirecl-service</artifactId>
<packaging>jar</packaging>
<name>empirecl-service</name>
<dependencies>
<dependency>
<groupId>com.netsol</groupId>
<artifactId>empirecl-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
------------------------------------------
dao模块maven清理安装成功,但是当我尝试使用service模块时,会产生如下异常:
The Dao module maven clean and install successfully, but when i trying to use service module, it will generate an following exception:
[ERROR] Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT: Could not find artifact com.netsol:empirecl:pom:0.0.1-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project empirecl-service: Could not resolve dependencies for project com.netsol:empirecl-service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.netsol:empirecl-dao:jar:0.0.1-SNAPSHOT
我正在尝试从网络上查找解决方案,但仍未找到解决方案.在 Eclipse 中,当我打开服务模块的 Dependency Hierarchy
时,它将 DAO 模块显示为文件夹而不是 jar.下面是服务模块的Dependency Hierarchy
的截图.
I am trying the find to solution from web, but still the solution is not found. In eclipse when i open the Dependency Hierarchy
of service module, it shown the DAO module as a folder not jar. below is the screen shot of Dependency Hierarchy
of service module.
推荐答案
如果有人回到这个问题,我认为这里的问题是未能首先安装父 pom,所有这些子模块都依赖它,所以 Maven Reactor 无法收集构建所需的依赖项子模块.
In case anybody comes back to this, I think the problem here was failing to install the parent pom first, which all these submodules depend on, so the Maven Reactor can't collect the necessary dependencies to build the submodule.
所以从根目录(这里是D:luna_workspaceempire_clubempirecl
)它可能只需要一个:
So from the root directory (here D:luna_workspaceempire_clubempirecl
) it probably just needs a:
mvn clean install
(旁白:<relativePath>../pom.xml</relativePath>
并不是真正需要的,因为 这是默认值).
(Aside: <relativePath>../pom.xml</relativePath>
is not really necessary as it's the default value).
这篇关于MavenError:无法在项目上执行目标:无法解决Maven Multimodule项目中的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!