简体   繁体   English

从Git导入多模块Maven项目到Eclipse / STS

[英]Importing multimodule maven project from Git into Eclipse/STS

I have been desperately trying to import a multimodule maven project from GIT into my (freshly installed) STS 3.9.4. 我一直在拼命地尝试从GIT导入多模块Maven项目到我的(新安装的)STS 3.9.4中。 During the last hours I tried lots of solutions that were posted on stack overflow, but none of them worked for me. 在过去的几个小时中,我尝试了很多在堆栈溢出时发布的解决方案,但是没有一个对我有用。

These are the steps I did: 这些是我执行的步骤:

  • git clone d the repo from the command line (intentionally, because it didn't work either when I used the GIT integration of STS) git clone从命令行git clone回购(故意,因为当我使用STS的GIT集成时它也不起作用)
  • imported the project via File / Import / Maven / Existing Maven Projects 通过File / Import / Maven / Existing Maven Projects Import Existing Maven Projects

After the project was imported, it looks like this: 导入项目后,如下所示: 项目结构

(please ignore the red icon at the top left, the problems persists even when this icon is not there) (请忽略左上角的红色图标,即使该图标不存在,问题仍然存在)

I can Run As / Maven Install any pom.xml , but when I try to edit java sourcecode Eclipse tells me The resource is not on the build path of a Java project . 我可以Run As / Maven Install 任何 pom.xml ,但是当我尝试编辑Java源代码时,Eclipse告诉我The resource is not on the build path of a Java project To fix this I tried: 为了解决这个问题,我尝试了:

  • convert to faceted form 转换为多面形式
  • added Java nature 增加了Java性质
  • Configure Build Path / Set as source folder Configure Build Path / Set as source folder
  • add buildcommand org.eclipse.jdt.core.javabuilder to .project buildcommand org.eclipse.jdt.core.javabuilder添加到.project

Being able to build is fine, but editing sourcecode without support for Organize Imports, Format Source, and so on is a real pain. 能够进行构建很好,但是在不支持“组织导入”,“格式化源”等的情况下编辑源代码实在是很痛苦。

The solution to this problem was somehow hidden, but in the end I have to say the reason was clear. 这个问题的解决方案某种程度上是隐藏的,但是最后我不得不说原因很明确。 After I checked with a different multimodule project ( https://github.com/Activiti/Activiti.git ), I was sure that my STS and other components don't suffer from a generic problem. 在检查了另一个多模块项目( https://github.com/Activiti/Activiti.git )之后,我确定我的STS和其他组件不会遇到一般性问题。 So the cause must be located in the project itself. 因此,原因必须位于项目本身中。

The multimodule project was setup correctly on the pom.xml level. pom.xml级别正确设置了多模块项目。 But the topmost pom.xml was modified: most of the modules had been commented out: 但是最顶层的pom.xml已被修改: 大多数模块已被注释掉: 注释掉pom中的模块

The developer who introduced that change didn't experience any problems because he kept his already existing workspace. 引入了该更改的开发人员没有遇到任何问题,因为他保留了已经存在的工作空间。 And the problem only occurs when a new workspace gets created and maven scans the pom files. 而且仅当创建了新的工作区并且maven扫描pom文件时,才会出现问题。

From your screenshot I assume the modules are nested within the directory of the reactor pom(=parent pom) and you have imported all of them as projects (reactor and modules). 从屏幕快照中,我假设模块嵌套在反应堆pom(= parent pom)的目录中,并且您已将所有模块都导入为项目(反应堆和模块)。

Don't add a java builder to the "reactor" project. 不要将Java构建器添加到“ reactor”项目中。

Make sure not to open the java files from the projects corresponding to the reactor pom, but from src folder within the corresponding module projects. 确保不要从对应于反应堆pom的项目中打开Java文件,而是从相应模块项目中的src文件夹中打开。

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

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