Eclipse 和 Maven 多模块项目的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3016103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:49:16  来源:igfitidea点击:

Problem with Eclipse and a Maven multi-module project

eclipsemaven-2multi-module

提问by earth

I have created a Maven project with the following structure:

我创建了一个具有以下结构的 Maven 项目:

+ root-project
  pom.xml (pom)
  + sub-projectA (jar)
  + sub-projectB (jar)

I have done the following steps:

我已经完成了以下步骤:

  1. mvn archetype:create –DgroupId=my.group.id –DartifactId=root-project
  2. mvn archetype:create –DgroupId=my.group.id –DartifactId=sub-projectA
  3. mvn archetype:create –DgroupId=my.group.id –DartifactId=sub-projectB
  1. mvn 原型:创建 –DgroupId=my.group.id –DartifactId=root-project
  2. mvn 原型:创建 –DgroupId=my.group.id –DartifactId=sub-projectA
  3. mvn 原型:创建 –DgroupId=my.group.id –DartifactId=sub-projectB

So I have, obviously, in the top-level pom.xml the following elements:

因此,显然,在顶级 pom.xml 中,我有以下元素:

  <modules>
    <module>sub-projectA</module>
    <module>sub-projectB</module>
  </modules>

The last step was:

最后一步是:

mvn eclipse:clean eclipse:eclipse

Now if I import the root-projectin Eclipse, it seems to look at my projects as resources and not like java projects.

现在,如果我在 Eclipse 中导入根项目,它似乎将我的项目视为资源而不是 java 项目。

However if I import each of child projects sub-projectAand sub-projectB, it looks them like java projects.

但是,如果我导入每个子项目 sub-projectAsub-projectB,它们看起来就像 java 项目。

This is a big problem for me because I have a deeper hierarchy. Any help would be appreciated!

这对我来说是一个大问题,因为我有更深的层次结构。任何帮助,将不胜感激!

回答by Pascal Thivent

The maven eclipse plugin does NOT support nested projects so you can't import the root-project and the nested modules (unless you move to a flat layout).

maven eclipse 插件不支持嵌套项目,因此您无法导入根项目和嵌套模块(除非您移动到平面布局)。

The alternative is to use m2eclipse(and you won't have any problems with a maven-typical nested tree). This is the preferred approach nowadays.

另一种方法是使用m2eclipse(使用maven 典型的嵌套树不会有任何问题)。这是当今的首选方法。

回答by Ravi Kant

Please follow these simple step's to configure project

请按照这些简单的步骤来配置项目

  1. Download project from maven project

  2. Inside ch-multi-spring->simple-parent

  1. Maven 项目下载项目

  2. 在 ch-multi-spring->simple-parent 里面

convert simple-parent to eclipse project using this command

使用此命令将 simple-parent 转换为 eclipse 项目

mvn eclipse:eclipse
  1. Import sample-parent in eclipse.

  2. For runing this project

    right click on simple-webapp->properties->deployment assemblly->project-> Then add all the dependent project.

  3. Now you can run this project.

  1. 在eclipse中导入sample-parent。

  2. 为了运行这个项目

    右键simple-webapp->properties->deployment assemblly->project-> 然后添加所有依赖的项目。

  3. 现在你可以运行这个项目了。

回答by James Oravec

I had a similar issue, and the following is what I did to solve it...

我有一个类似的问题,以下是我为解决它所做的......

I had the parent project open as well as the child projects. The child projects would build fine and not show any problems, however the parent showed the child projects as "resource folders" and they showed as having problems.

我打开了父项目以及子项目。子项目可以正常构建并且不会显示任何问题,但是父项目将子项目显示为“资源文件夹”并且它们显示为有问题。

Solution was to right click on each of the child projects in the parent project -> Properties -> Resource -> Check "derived"

解决方案是右键单击父项目中的每个子项目 -> 属性 -> 资源 -> 选中“派生”

After you do this, clean/rebuild and you should be good.

执行此操作后,清理/重建,您应该会很好。