简体   繁体   English

将Maven多模块项目导入Eclipse

[英]Import Maven multi-module project into Eclipse

How do I properly import Maven multi-module project into Eclipse?如何将 Maven 多模块项目正确导入 Eclipse? When I import new Maven project and select the parent pom, I can see the submodules under the parent pom and they are visible in package explorer and project explorer.当我导入新的 Maven 项目并选择父 pom 时,我可以看到父 pom 下的子模块,它们在包资源管理器和项目资源管理器中可见。 However, they are presented as deep directory structure, as if eclipse doesn't know they are Java projects.但是,它们以深层目录结构呈现,就好像 eclipse 不知道它们是 Java 项目一样。

When I expand the submodule project, I don't see the Java packages shortcuts as I would have opened a single Maven project.当我展开子模块项目时,我没有看到 Java 包快捷方式,因为我会打开一个 Maven 项目。 I only see it as a deep directory structure.我只将其视为深层目录结构。 How do I import multimodule Maven project and open the submodule project to take advantage of Eclipse Java project features?如何导入多模块 Maven 项目并打开子模块项目以利用 Eclipse Java 项目功能?

  • Install M2E Plugin from Market if it is not already installed如果尚未安装,请从 Market 安装 M2E 插件
  • From Eclipse IDE choose "File" and "Import" from toolbar.在 Eclipse IDE 中,从工具栏中选择“文件”和“导入”。 That should lead you to a pop up.这应该会导致您弹出一个窗口。
  • Type "Existing Maven Project", or navigate to this voice under Maven settings.键入“Existing Maven Project”,或导航到 Maven 设置下的此语音。
  • Then select main pom project from the import menu, and be sure to select entire tree of projects under it.然后从导入菜单中选择主 pom 项目,并确保选择其下的整个项目树。

Before to approach this clean the IDE from current wrong imported project deleting its maven root pom project and every sub modules, but leave them in the disk obviously.在从当前错误导入的项目中清除 IDE 之前,删除其 maven root pom 项目和每个子模块,但显然将它们留在磁盘中。 I don't recommend the "Convert" options as sometimes doesn't lead to clean results, especially with big and messy projects.我不推荐“转换”选项,因为有时不会产生干净的结果,尤其是对于大而杂乱的项目。 That should do the trick.那应该可以解决问题。 Let me know if this solves your problem.如果这能解决您的问题,请告诉我。

For everyone who still have the same issue, follow these steps:对于仍然有相同问题的每个人,请按照以下步骤操作:

  1. Open Import Existing Maven Project wizard打开Import Existing Maven Project向导
  2. Select the Parent POM.xml only and click Finish仅选择 Parent POM.xml并单击Finish
  3. Foreach child project, Right Click on the project folder, then click on Import and select his POM.xml file Foreach子项目, Right Click项目文件夹,然后单击Import并选择他的POM.xml文件

Hope it helps !希望它有帮助! Good Luck !祝你好运!

If you are using git or any version control.如果您使用 git 或任何版本控制。 Clone the repository first in local.首先在本地克隆存储库。

Steps already explain by @Black Jack. @Black Jack 已经解释了步骤。 Adding image to support添加图像以支持

在此处输入图片说明

Step 1第 1 步

  • Navigate to project folder.导航到项目文件夹。
  • Open command prompt (or shell)打开命令提示符(或 shell)
  • Run mvn eclipse:eclipse运行mvn eclipse:eclipse

Step 2第 2 步

  • Open eclipse IDE打开日食IDE
  • Open project from File > Open Projects From File System...File > Open Projects From File System...
  • Select folder of project containing parent pom.xml file选择包含父pom.xml文件的项目文件夹

Step 3第 3 步

  • Run Project > Clean from Menu运行Project > Clean从菜单Project > Clean

Step 4第 4 步

  • Run File> Restrat From Menu运行File> Restrat从菜单File> Restrat

Solved my problem in Eclipse 2019-06(4.12.0) and 2018-12(4.10.0)解决了我在 Eclipse 2019-06(4.12.0) 和 2018-12(4.10.0) 中的问题

Important trick重要的技巧

When you start to search for files in 'open resource' (for example using Ctrl + Shift + R ) eclipse will show file from two address.当您开始在“打开资源”中搜索文件时(例如使用Ctrl + Shift + R ),eclipse 将显示来自两个地址的文件。 for example MySampleFile will be available under:例如MySampleFile将在以下位置可用:

  • parent-module/sub-module/src/main/java/.../MySampleFile and parent-module/sub-module/src/main/java/.../MySampleFile
  • sub-module/src/main/java/.../MySampleFile

Use second one .使用第二个 Opening file with first one will not activate IDE features on that file.使用第一个打开文件不会激活该文件的 IDE 功能。

First, import the parent project.首先,导入父项目。 Then, right click on it at the package/project explorer, go to Configure and then click the Configure and Detected Nested Projects... , on the window that will appear click Finish and you're gold.然后,在包/项目资源管理器中右键单击它,转到“配置” ,然后单击“配置和检测到的嵌套项目...” ,在出现的窗口中单击“完成” ,您就成功了。

Also worth mentioning, Package Explorer won't show it nested, use Project Explorer instead.还值得一提的是,Package Explorer 不会显示嵌套,而是使用 Project Explorer。

Have a nice day.有一个美好的一天。

To add a few on top of Black Jack's answer, ensure that the parent pom in the root of the directory that contains sub-projects, contains a modules section:要在 Black Jack 的答案之上添加一些内容,请确保包含子项目的目录根目录中的父 pom 包含一个模块部分:

<modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
</modules>

So, after the import, unline IntelliJ, Eclipse opens the sub-modules as separate projects, apart from the main root project.因此,在导入之后,取消 IntelliJ,Eclipse 将子模块作为单独的项目打开,除了主根项目。

Hope this helps!希望这有帮助!

Follow the steps按照步骤操作

  1. Choose file menu选择文件菜单
  2. Click on import点击import
  3. Select project right click then Convert --> Convert to maven project选择项目右键单击然后转换 --> 转换为 maven 项目
  4. Click on import then type or select Existing Maven Project单击import然后键入或选择Existing Maven Project

Now your moduled project in you workbench.现在您的工作台中的模块化项目。 If you have any query we can discuss.如果您有任何疑问,我们可以讨论。

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

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