Java Maven:尝试使用依赖项将项目包含在另一个项目中时找不到工件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40763263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven: Could Not find Artifact when trying to include a project in another one using dependencies
提问by Hani Goc
Problem description
问题描述
I have a project called reservationVol
which I want to include in an mvc spring project called reservationVolMvc
. I compiled and tested reservationVol
on eclipse. I also use the maven commands: mvn compil
e and mvn package
. All tests ran successfully.
我有一个名为的项目reservationVol
,我想将其包含在名为 .mvc 的 spring 项目中reservationVolMvc
。我reservationVol
在eclipse上编译和测试。我也使用 maven 命令:mvn compil
e 和mvn package
. 所有测试都成功运行。
When I tried to compile reservationVolMvc
using the mvn compile command i get the following error:
当我尝试reservationVolMvc
使用 mvn compile 命令进行编译时,出现以下错误:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building reservationVolSpring 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for hani.reservationVol:reservationVol:jar:1.0-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.688 s
[INFO] Finished at: 2016-11-23T12:25:21+01:00
[INFO] Final Memory: 6M/77M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project reservationVolSpring: Could not resolve dependencies for project formation.addstones:reservationVolSpring:war:1.0-SNAPSHOT: Could not find artifact hani.reservationVol:reservationVol:jar:1.0-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The following pom.xmlfiles represent the dependencies for respectively reservationVol
and reservationVolMvc
. I included the project ReservationVol
in reservationVolMvc
by using the following:
下面的pom.xml文件代表分别的依赖reservationVol
和reservationVolMvc
。我包括在该项目ReservationVol
中reservationVolMvc
使用的情况如下:
<dependency>
<groupId>hani.reservationVol</groupId>
<artifactId>reservationVol</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
ReservationVol
预订量
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hani.reservationVol</groupId>
<artifactId>reservationVol</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>reservationVol</name>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
reservationVolMvc
保留卷
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>formation.addstones</groupId>
<artifactId>reservationVolSpring</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>reservationVolSpring</name>
<dependencies>
<dependency>
<groupId>hani.reservationVol</groupId>
<artifactId>reservationVol</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fasterxml.Hymanson.core</groupId>
<artifactId>Hymanson-databind</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.2.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
采纳答案by JoB?N
Do a mvn clean install
.
This will clean whatever created from the previous build, then build your project and add the jars to your local maven repository (.m2\repository)
做一个mvn clean install
。
这将清除先前构建中创建的任何内容,然后构建您的项目并将 jar 添加到您的本地 maven 存储库 (.m2\repository)
回答by Krithika
I also faced the same problem...................Issue got resolved
Do a maven clean and install of the child project and then try
我也遇到了同样的问题.........问题得到解决
做一个 maven clean 并安装子项目,然后尝试
maven clean and install of parent project.
Maven 清理并安装父项目。
For reference watch these videos https://www.youtube.com/watch?v=2aNC1EAnpqohttps://www.youtube.com/watch?v=EMfd2FwKKHY
参考观看这些视频 https://www.youtube.com/watch?v=2aNC1EAnpqo https://www.youtube.com/watch?v=EMfd2FwKKHY
回答by J.Leupp
I was facing the same issue, I had a parent project that would fail on the Clean Install of a dependent project.
我遇到了同样的问题,我有一个父项目在依赖项目的全新安装时会失败。
I tried all of the above solutions to no avail, running clean install both in eclipse and from command line.
我尝试了上述所有解决方案都无济于事,在 eclipse 和命令行中运行全新安装。
I was able to solve by navigating to the Child Project and Running the following
我能够通过导航到 Child Project 并运行以下命令来解决
- Cleaning the project
mvn clean
- Setting as eclipse project
mvn eclipse:eclipse
(this forced download of missing jars) - Follow by clean install of Child project
mvn clean install -U
- Finally clean install on parent project
mvn clean install -DskipTests -P(if necessary a profile here) -U
- 清理项目
mvn clean
- 设置为 eclipse 项目
mvn eclipse:eclipse
(强制下载丢失的 jars) - 接下来是全新安装 Child 项目
mvn clean install -U
- 最后在父项目上进行全新安装
mvn clean install -DskipTests -P(if necessary a profile here) -U
This helped when maven was not downloading jar's properly listed in the pom.xml, I was not able to find why clean install with Update Snapshots/etc. did not download the missing jars.
当 maven 没有下载在 pom.xml 中正确列出的 jar 时,这会有所帮助,我无法找到为什么使用更新快照/等进行全新安装。没有下载丢失的罐子。