简体   繁体   English

Java 运行时依赖项目错误 Maven 安装

[英]Java Dependent Projects Error When Running Maven Install

I am getting the following error when running maven install运行 maven 安装时出现以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Ice-Redalert-Web: Compilation failure [ERROR] /D:/ProjectCode/RedAlert ICE/property-builder-front-ice/src/main/java/com/informationcatalyst/redalert/webapplication/service/IceApplicationBuilderImpl.java:[22,1] package com.informationcatalyst.icekeywords does not exist [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Ice-Redalert-Web: 编译失败 [错误] /D:/ProjectCode/ RedAlert ICE/property-builder-front-ice/src/main/java/com/informationcatalyst/redalert/webapplication/service/IceApplicationBuilderImpl.java:[22,1] package com.informationcatalyst.icekeywords does not exist [ERROR] -> [帮助 1] [错误] [错误] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 [ERROR] Re-run Maven using the -X switch to enable full debug logging. [错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。 [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles [ERROR] [ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章

There are two projects.有两个项目。 The main project and one it depends on.主要项目和它所依赖的项目。 When running maven install on my laptop, the above error comes up.在我的笔记本电脑上运行 maven install 时,出现上述错误。 However when my co-worker takes an identical copy of both projects and runs maven install it works just fine.但是,当我的同事获取两个项目的相同副本并运行 maven 安装时,它工作得很好。

There must be something wrong on my setup for this to be an issue.我的设置一定有问题,这是一个问题。 I don't know where to start.我不知道从哪里开始。 Myself and co-worker who has lots of java experience checked the setup and naming and can't see a problem.我和有很多 java 经验的同事检查了设置和命名,没有发现问题。 But there clearly is an issue.但显然有一个问题。

The main project has the dependency as pom entry as主项目具有作为 pom 条目的依赖项

    <dependency>
    <groupId>com.undergroundit</groupId>
    <artifactId>train</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>

The header on the pom relating to the above reference is与上述参考相关的pom上的header是

<groupId>com.undergroundit</groupId>
<artifactId>train</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>train</name>
<packaging>jar</packaging>

I am using Eclipse, but I get the same issue arising in Intellij.我正在使用 Eclipse,但在 Intellij 中出现了同样的问题。

We checked the.m2 folder for the contents to make sure it was matching the pom entries.我们检查了 .m2 文件夹中的内容,以确保它与 pom 条目匹配。

Any guidance on what to check or what the problem might be is appreciated.任何有关检查内容或可能存在的问题的指导都将受到赞赏。 Thanks谢谢

I would suggest to either run the build with clean and/or to delete the maven.m2 cache.我建议使用 clean 运行构建和/或删除 maven.m2 缓存。 I've had similar errors with the maven cache. maven 缓存也有类似的错误。 Are you sure you and your co-worker have the identical source?你确定你和你的同事有相同的来源吗? The error message suggest a missing package, which may indicate that you are looking at the wrong error.错误消息提示缺少 package,这可能表明您正在查看错误的错误。

The problem turns out to be that although the dependent project would compile in the IDE it wasn't including the class files.问题是,虽然依赖项目将在 IDE 中编译,但它不包括 class 文件。 Therefore the projects depending on it didn't have enough information to use the dependency.因此依赖它的项目没有足够的信息来使用依赖。

The... in the mainClass element below is to anonymise the name.下面 mainClass 元素中的 ... 是为了匿名化名称。

<build>
<plugins>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
  </configuration>
</plugin>
 <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-dependency-plugin</artifactId>
           <executions>
               <execution>
                   <id>copy-dependencies</id>
                   <phase>prepare-package</phase>
                   <goals>
                       <goal>copy-dependencies</goal>
                   </goals>
                   <configuration>
                       <outputDirectory>
                           ${project.build.directory}/lib
                       </outputDirectory>
                   </configuration>
               </execution>
           </executions>
       </plugin>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-jar-plugin</artifactId>
           <configuration>
               <archive>
                   <manifest>
                       <addClasspath>true</addClasspath>
                       <classpathPrefix>lib/</classpathPrefix>
                       <mainClass>...</mainClass>
                   </manifest>
               </archive>
           </configuration>
       </plugin>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM