Maven:尝试使用依赖项在另一个项目中包含项目时找不到工件

Han*_*Goc 6 java eclipse spring maven

问题描述

我有一个项目reservationVol,我希望将其包含在一个名为的mvc spring项目中reservationVolMvc.我reservationVol在eclipse上编译和测试.我也使用maven命令:mvn compile和mvn package.所有测试都成功运行.

当我尝试reservationVolMvc使用mvn编译命令进行编译时,我收到以下错误:

[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
Run Code Online (Sandbox Code Playgroud)

下面的pom.xml 文件代表分别的依赖reservationVolreservationVolMvc.我包括在该项目ReservationVolreservationVolMvc使用下列内容:

<dependency>
    <groupId>hani.reservationVol</groupId>
    <artifactId>reservationVol</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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.jackson.core</groupId>
            <artifactId>jackson-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>
Run Code Online (Sandbox Code Playgroud)

Job*_*eph 10

做一个mvn clean install.
这将清除从先前构建创建的任何内容,然后构建项目并将jar添加到本地maven存储库(.m2\repository)


J.L*_*upp 7

我面临着同样的问题,我有一个父项目在依赖项目的全新安装中会失败。

我尝试了上述所有解决方案均无效,在 eclipse 和命令行中运行 clean install 。

我能够通过导航到子项目并运行以下命令来解决

  1. 清理项目mvn clean
  2. 设置为 eclipse 项目mvn eclipse:eclipse(这会强制下载丢失的 jars)
  3. 接下来是子项目的全新安装mvn clean install -U
  4. 最后在父项目上进行全新安装mvn clean install -DskipTests -P(if necessary a profile here) -U

当 maven 没有下载 pom.xml 中正确列出的 jar 时,这会有所帮助,我无法找到为什么使用更新快照/等进行干净安装。没有下载丢失的罐子。


小智 5

我也遇到了同样的问题..........问题得到解决请
执行maven清理并安装子项目,然后尝试

maven清理并安装父项目。

供参考,请观看这​​些视频 https://www.youtube.com/watch?v=2aNC1EAnpqo https://www.youtube.com/watch?v=EMfd2FwKKHY