如何在 Eclipse 中配置 Java EE maven 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15683299/
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 20:17:02  来源:igfitidea点击:

How do I configure a Java EE maven project in Eclipse?

eclipsemavenjava-ee-6

提问by javabeats

I know Maven pretty well, but I usually work with Netbeans, which makes it quite easy to deploy Java EE applications - and handle hot deployment of any changes.

我非常了解 Maven,但我通常使用 Netbeans,这使得部署 Java EE 应用程序变得非常容易 - 并处理任何更改的热部署。

The team I work with now uses Eclipse as their IDE of choice, but none of them has worked with Maven projects before; so I need to know how to correctly add Eclipse's project facets to the maven projects we have, in order to support (hot) deployment through WTP. We are using Weblogic 12c for this particular endeavour.

我工作的团队现在使用 Eclipse 作为他们选择的 IDE,但他们之前都没有使用过 Maven 项目;所以我需要知道如何将 Eclipse 的项目方面正确添加到我们拥有的 Maven 项目中,以便通过 WTP 支持(热)部署。我们正在使用 Weblogic 12c 来完成这项特殊的工作。

Our project layout is as simple as it gets:

我们的项目布局非常简单:

super-project (pom)
    project-ear (pom)
    project-ejb (pom)
    project-web (pom)

Thanks for any resource you can point me to.

感谢您可以指向我的任何资源。

回答by Charlee Chitsuk

I suppose that you've installed all required plugins to the Eclipse already. As @Micha? Politowski mentions, M2E, M2E-WTPand so on.

我想您已经为 Eclipse 安装了所有必需的插件。作为@Micha?Politowski 提到,M2EM2E-WTP等等。

Add Archetype Catalog

添加原型目录

  1. Go to menu Window--->Preferences.

  2. At the Preferences window, select Maven---->Archetypes,

  3. On the Right Panel, click Add Remote Catalog...button.

  4. At the Remote Archetype Catalog windowsenter the following: -

    1. Catalog file: http://repo.maven.apache.org/maven2
    2. DescriptionMaven Central
  5. Add more remote catalog.

    1. Catalog file: http://download.java.net/maven/2
    2. DescriptionJava.Net
  6. Click OKto apply change.

  1. 转到菜单Window--->Preferences

  2. Preferences window,选择Maven---->Archetypes

  3. 在 上Right Panel,单击Add Remote Catalog...按钮。

  4. Remote Archetype Catalog windows输入以下内容: -

    1. Catalog filehttp: //repo.maven.apache.org/maven2
    2. DescriptionMaven中心
  5. 添加更多远程目录。

    1. Catalog filehttp: //download.java.net/maven/2
    2. Description网络
  6. 单击OK以应用更改。

Create the parent project

创建父项目

  1. Go to menu File ---> New ---> Other.
  2. At the Select Wizard Windows, select Maven ---> Project.
  3. Click next and enter the required information so that we are at the New Maven Project.
  4. At the Filtertextbox, enter pom
  5. Choose org.codehaus.mojo.archetypes:pom-root:1.1
  6. Click next and enter the required information so that the parent creation is finished.
  1. 转到菜单File ---> New ---> Other
  2. 在 处Select Wizard Windows,选择Maven ---> Project
  3. 单击下一步并输入所需信息,以便我们在New Maven Project.
  4. Filter文本框中输入pom
  5. 选择 org.codehaus.mojo.archetypes:pom-root:1.1
  6. 单击下一步并输入所需信息,以便完成父创建。

Create the child project

创建子项目

  1. Right click at the parent project and select New ---> Other.
    1. At the Select Wizard Windows, select Maven ---> Project.
  2. Click next and enter the required information so that we are at the New Maven Project.
  3. You will see that the Parent Project= MY PARENT
  4. Enter the Module name, e.g. my-ear, my-ejb or my-web. Then click Nextbutton,
  5. At the Filtertextbox, enter some of the following
    1. org.codehaus.mojo.archetypes:webapp-javaee6:1.5
    2. org.codehaus.mojo.archetypes:ejb-javaee6:1.5
    3. org.codehaus.mojo.archetypes:ear-javaee6:1.5
  6. Click next and enter the required information so that the child creation is finished.
  1. 右键单击父项目并选择New ---> Other
    1. 在 处Select Wizard Windows,选择Maven ---> Project
  2. 单击下一步并输入所需信息,以便我们在New Maven Project.
  3. 你会看到Parent Project=MY PARENT
  4. 输入Module name,例如 my-ear、my-ejb 或 my-web。然后点击Next按钮,
  5. Filter文本框中,输入以下一些内容
    1. org.codehaus.mojo.archetypes:webapp-javaee6:1.5
    2. org.codehaus.mojo.archetypes:ejb-javaee6:1.5
    3. org.codehaus.mojo.archetypes:ear-javaee6:1.5
  6. 单击下一步并输入所需信息,以便完成子创建。

Summary

概括

I've used both NetBeans 7.x and Eclipse Juno together. When I move to Eclipse I've face the issue as same as your. Then I've captured the steps above from NetBeans logs one by one, and do the same thing manually by using Eclipse.

我同时使用了 NetBeans 7.x 和 Eclipse Juno。当我搬到 Eclipse 时,我遇到了和你一样的问题。然后我从 NetBeans 日志中一一捕获了上述步骤,并使用 Eclipse 手动执行相同的操作。

I hope this may help.

我希望这会有所帮助。

回答by Ari

I would make one small change:

我会做一个小的改变:

Create the child project

创建子项目

Right click at the parent project and select New ---> Other.
    At the Select Wizard Windows, select Maven ---> **Maven Module**

This way it will automatically recognize this as a child project of the parent.

这样它会自动将其识别为父项目的子项目。