简体   繁体   English

eclipse中的多模块maven项目结构

[英]multi module maven project structure in eclipse

I have two modules under a main project我在一个主项目下有两个模块

main主要的
| |
| |
--module-a --模块-a
| |
| |
--module-b --模块-b

I created it using eclipse->new ->Maven project, eclipse->new->maven module.我使用 eclipse->new ->Maven 项目,eclipse->new->maven 模块创建了它。

The structure in the file system looks correct.文件系统中的结构看起来是正确的。 But in eclipse, it shows module-a, module-b as two new projects in the package explorer.但是在 eclipse 中,它在包资源管理器中将 module-a、module-b 显示为两个新项目。

My main project looks like this.我的主要项目是这样的。

在此处输入图片说明

I have seen few multi module projects where, the modules are present within the main project in package explorer.我见过几个多模块项目,其中模块存在于包资源管理器的主项目中。 The main project had主要项目有

module-a/src/main/java模块-a/src/main/java
module-a/src/test/java模块-a/src/test/java
module-a/src/resources/java模块-a/src/resources/java
module-b/src/main/java模块-b/src/main/java
module-b/src/test/java模块-b/src/test/java
module-b/src/resources/java.模块-b/src/resources/java。

How do I convert my project to look like this ?如何将我的项目转换成这样?

Starting from Eclipse 4.5.M5 (that you can already download at http://eclipse.org/downloads ), the Project Explorer view has a parameter to show projects hierarchically, to better handle such case.从 Eclipse 4.5.M5(您已经可以在http://eclipse.org/downloads下载)开始,Project Explorer 视图有一个参数来分层显示项目,以更好地处理这种情况。 See https://www.eclipse.org/eclipse/news/4.5/M5/ for details.有关详细信息,请参阅https://www.eclipse.org/eclipse/news/4.5/M5/

You will find if you navigate the actual file system (oe use the 'navigator' view in eclipse) that the sub modules do in fact exist underneath the main parent project folder.如果您浏览实际的文件系统(即在 eclipse 中使用“导航器”视图),您会发现子模块确实存在于主父项目文件夹下。

Eclipse is nice enough (clever enough or whatever) to pull them out when you use the 'package explorer' view.当您使用“包资源管理器”视图时,Eclipse 足够好(足够聪明或其他什么)将它们拉出来。 I guess this makes it easier to find and navigate your way aournd a highly modular project.我想这使得在高度模块化的项目中更容易找到和导航你的方式。

However if you set up your Parent POM correctly you can have a flat structure to your modular project if you so desire (I haven't as yet been able to get this to work, so far I think it is related to the sub module classpaths or something?).但是,如果您正确设置了您的父 POM,您可以根据需要为您的模块化项目创建一个扁平结构(我还没有能够让它工作,到目前为止我认为它与子模块类路径有关或者其他的东西?)。

David.大卫。

I solved this problem as follows:我解决了这个问题如下:

Under the "Project Explorer" click on the "View Menu" (little triangle) and select "Filters and Customization..."在“项目资源管理器”下单击“查看菜单”(小三角形)并选择“过滤器和自定义...”

在此处输入图片说明

Under the "Content" tab tick "Nested Projects"在“内容”选项卡下勾选“嵌套项目”

在此处输入图片说明

Finally, Under the "Pre-set filters" tab tick "Nested Projects: hide folders when projects is shown as nested" and "Nested Projects: hide-top-level project if shown as nested".最后,在“预设过滤器”选项卡下勾选“嵌套项目:当项目显示为嵌套时隐藏文件夹”和“嵌套项目:如果显示为嵌套则隐藏顶级项目”。

在此处输入图片说明

By doing that I come up with the following structure.通过这样做,我想出了以下结构。

在此处输入图片说明

I used a Spring Tool Suite 3: Version: 3.9.11我使用的是 Spring Tool Suite 3:版本:3.9.11

You can do this in earlier versions of eclipse as well.您也可以在早期版本的 eclipse 中执行此操作。 Close and Remove the sub-module projects (as they are already present in the parent folder).关闭并删除子模块项目(因为它们已经存在于父文件夹中)。 Now click on Properties on the main project -> Project Facets -> Convert to faceted form.现在单击主项目上的 Properties -> Project Facets -> Convert to faceted form。 This will detect Java automatically, Click on Apply, OK.这将自动检测 Java,单击应用,确定。 Now you can see that these modules are created with Source folders现在您可以看到这些模块是使用 Source 文件夹创建的

Basically, Eclipse does not support the Maven way of structuring projects.基本上,Eclipse 不支持构建项目的 Maven 方式。

By using the M2E it is possible to execute Maven as part of the build, but that way you lose the project management and incremental build capabilities of Eclipse.通过使用 M2E,可以将 Maven 作为构建的一部分执行,但是这样您就失去了 Eclipse 的项目管理和增量构建功能。

You can also simply use the Eclipse layout in the IDE, and build with Maven in the build server, but that way you have to make sure the two build are identical.您也可以简单地在 IDE 中使用 Eclipse 布局,并在构建服务器中使用 Maven 进行构建,但这样您必须确保两个构建是相同的。

I have seen few multi module projects where, the modules are present within the main project in package explorer.我见过几个多模块项目,其中模块存在于包资源管理器的主项目中。

Thats what do maven eclipse plugin.这就是 maven eclipse 插件的作用。 It just create single project with multiple source directories for each module of maven multimodule project.它只是为 maven 多模块项目的每个模块创建具有多个源目录的单个项目。

If you want to see some hierarchical structure in eclipse - use working sets.如果你想在 Eclipse 中看到一些层次结构 - 使用工作集。 Create working set with name of parent, add module-a and module-b to it and visually it will be separated from other projects in eclipse workspace.使用父名称创建工作集,向其中添加模块 a 和模块 b,并且在视觉上它将与 eclipse 工作区中的其他项目分开。

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

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