简体   繁体   English

Maven 模块的 Eclipse 设置

[英]Eclipse settings for maven modules

I cloned the maven project to my local disk.我将 Maven 项目克隆到我的本地磁盘。 The project has 3 modules as well as a parent project.该项目有 3 个模块以及一个父项目。 i marked the 3 modules with the 3 colors-- the 4th, blue color is the project itself.我用 3 种颜色标记了 3 个模块——第四个,蓝色是项目本身。

The project is running all fine on maven both on Eclipse and on command line.该项目在 Eclipse 和命令行上的 Maven 上运行良好。 When i do a mvn install on Eclipse, the project is built and all the tests are run successfully -- i see the good old BUILD SUCCESS report of maven on Eclipse console.当我在 Eclipse 上执行mvn install时,项目已构建并且所有测试都成功运行——我在 Eclipse 控制台上看到了 maven 的旧版BUILD SUCCESS报告。

The problem is -- the modules are all messed up.问题是——模块都搞砸了。 (this "messed up" is the best way i can put it for now.) Eclipse doesn't recognize the dependencies between modules and gives checked errors to some of the code that use outside dependencies. (这个“搞砸了”是我现在可以说的最好的方式。)Eclipse 无法识别模块之间的依赖关系,并为一些使用外部依赖关系的代码提供检查错误。

At one place-- lombok @Getter is used in one class.在一个地方@Getter用于一个班级。 import lombok.Getter; is seen by the compiler-- no checked error to that.被编译器看到——没有检查错误。 but eclipse doesn't recognize the getter declaration of lombok, say getField() for the field field .但是 eclipse 无法识别 lombok 的 getter 声明,比如字段field getField() i know this because : a) in the class itself-- gives a warning that .. the private field field isn't used.我知道这一点是因为:a) 在类本身中 - 发出警告,提示.. 未使用私有字段field b) gives a checked error to getField() a reference from another class. b) 向getField()提供来自另一个类的引用的已检查错误。 Thought this might be an interesting example to how the dependencies are "working".认为这可能是一个关于依赖项如何“工作”的有趣示例。 i'm guessing one dependency that lombok is using is intercepted somewhere along the way to give this inconsistency.我猜 lombok 正在使用的一个依赖项在途中的某个地方被拦截,以产生这种不一致。

Following is the project root directory structure on disk.以下是磁盘上的项目根目录结构。 (the 3 colors are the 3 modules, have to hide the names for confidentiality): (3种颜色是3个模块,为了保密,必须隐藏名称):

在此处输入图片说明

the 3 modules are defined in the pom.xml as follows:这 3 个模块在 pom.xml 中定义如下:

在此处输入图片说明

i see the following in Eclipse project explorer:我在 Eclipse 项目资源管理器中看到以下内容:

在此处输入图片说明

so in the Project explorer, the 2 modules/tests (green & yellow) that have java dir, ie src/main/java appear twice.所以在项目资源管理器中,具有 java 目录的 2 个模块/测试(绿色和黄色),即src/main/java出现两次。 the orange module has only src/main/resources and no src/main/java .橙色模块只有src/main/resources ,没有src/main/java

In the second occurrences of the modules in the project explorer (the image above), there are no dependencies of any kind, not even Java itself and hence all those red dots all around (compiler errors).在项目资源管理器(上图)中第二次出现模块时,没有任何类型的依赖项,甚至没有 Java 本身,因此周围都是红点(编译器错误)。 The first occurrences of modules have Referenced Libraries and no Maven Dependencies :第一次出现的模块有Referenced Libraries并且没有Maven Dependencies

在此处输入图片说明

How to fix this project so that i can code and run in Eclipse?如何修复这个项目,以便我可以在 Eclipse 中编码和运行? Just to pin down-- project configuration is all fine and it runs successfully on maven.只是为了确定 - 项目配置一切正常,并且在 maven 上成功运行。 the problem is Eclipse's own settings on it.问题是 Eclipse 自己的设置。

so far i tried the following:到目前为止,我尝试了以下操作:

  • made the project faceted and added Java as the only one to its facets使项目多面并添加 Java 作为其多面的唯一一个
  • imported as Maven project -- File > Import > Maven > Existing Maven Projects导入为 Maven 项目 -- File > Import > Maven > Existing Maven Projects
  • ran mvn eclipse:eclipse on its pom.xml在其 pom.xml 上运行mvn eclipse:eclipse

Wasn't even seeing the Build path before these.在这些之前甚至没有看到Build path

i'd appreciate the help-- wore me out.我很感激你的帮助——让我筋疲力尽。
everyone else on the project is IntelliJ developer-- no workspace to compare with.项目中的其他人都是 IntelliJ 开发人员——没有工作空间可以比较。

i've seen Importing Maven project into Eclipse and some other useful discussions.我已经看到将 Maven 项目导入 Eclipse以及其他一些有用的讨论。

i'm not sure whether i should post .project, .settings and some other file contents also.我不确定我是否也应该发布 .project、.settings 和其他一些文件内容。 will do if necessary.必要时会做。

TIA. TIA。

Make sure to not only import the parent pom.xml , but also the Maven modules as projects into Eclipse .确保不仅pom.xml导入还将 Maven 模块作为项目导入到 Eclipse 中 To do this in one go, use要一次性完成此操作,请使用

  • File > Open Projects from File System... or文件 > 从文件系统打开项目...
  • in the Git Repositories view right-click the root folder and choose Import Projects...Git Repositories视图中右键单击根文件夹并选择Import Projects...

Make also sure Lombok has been installed into Eclipse , otherwise Eclipse's own incremental compiler would not generate eg getter and setter methods that are defined by Lombok annotations.还要确保Lombok 已安装到 Eclipse 中,否则 Eclipse 自己的增量编译器将不会生成例如由 Lombok 注释定义的 getter 和 setter 方法。 See the Lombok documentation of how to install Lombok into Eclipse .请参阅有关如何将 Lombok 安装到 Eclipse 中Lombok 文档 If you have installed Lombok after importing the projects, it might be that you need to do a Project > Clean... or close and reopen again the projects (via the right-click menu).如果您在导入项目后安装了 Lombok,则可能需要执行Project > Clean...或关闭并重新打开项目(通过右键单击菜单)。

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

相关问题 Maven插件不使用Eclipse的代理设置 - Maven plugin not using Eclipse's proxy settings Eclipse中针对多个模块的Maven依赖项解析 - Maven dependency resolution in eclipse for multiple modules Eclipse 中 Java Maven 模块的行为不一致 - Inconsistent behavior of Java Maven Modules in Eclipse Eclipse、Maven:模块在 -source 8 中不受支持(使用 -source 9 或更高版本来启用模块) - Eclipse, Maven: Modules are not supported in -source 8 (use -source 9 or higher to enable modules) Eclipse 2019-03 关于 Java 模块和 maven - Eclipse 2019-03 regarding Java modules and maven 在Maven Eclipse中的其他模块中看不到相关模块的更改 - Changes in dependent modules cannot be seen in other module in Maven Eclipse 使用模块将Eclipse动态Web项目转换为Maven项目 - Converting Eclipse dynamic web project to maven project with modules 使用Maven或JBoss工具在Eclipse上添加JBoss AS 7模块 - Adding JBoss AS 7 modules on Eclipse using Maven or JBoss Tools 具有多模块的 Maven 项目无法找到模块的 pom.xml - Jenkins/Eclipse - Maven Project with multi modules is unable to find pom.xml of modules - Jenkins/Eclipse 使用 Maven 和 Eclipse 测试白盒单元测试 Java 模块的依赖项 - Test dependencies for white-box unit testing Java modules with Maven and Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM