如何在 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
How do I configure a Java EE maven project in Eclipse?
提问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 提到,M2E,M2E-WTP等等。
Add Archetype Catalog
添加原型目录
Go to menu
Window--->Preferences
.At the
Preferences window
, selectMaven---->Archetypes
,On the
Right Panel
, clickAdd Remote Catalog...
button.At the
Remote Archetype Catalog windows
enter the following: -Catalog file
: http://repo.maven.apache.org/maven2Description
Maven Central
Add more remote catalog.
Catalog file
: http://download.java.net/maven/2Description
Java.Net
Click
OK
to apply change.
转到菜单
Window--->Preferences
。在
Preferences window
,选择Maven---->Archetypes
,在 上
Right Panel
,单击Add Remote Catalog...
按钮。在
Remote Archetype Catalog windows
输入以下内容: -Catalog file
:http: //repo.maven.apache.org/maven2Description
Maven中心
添加更多远程目录。
Catalog file
:http: //download.java.net/maven/2Description
网络
单击
OK
以应用更改。
Create the parent project
创建父项目
- Go to menu
File ---> New ---> Other
. - At the
Select Wizard Windows
, selectMaven ---> Project
. - Click next and enter the required information so that we are at the
New Maven Project
. - At the
Filter
textbox, enterpom
- Choose
org.codehaus.mojo.archetypes:pom-root:1.1
- Click next and enter the required information so that the parent creation is finished.
- 转到菜单
File ---> New ---> Other
。 - 在 处
Select Wizard Windows
,选择Maven ---> Project
。 - 单击下一步并输入所需信息,以便我们在
New Maven Project
. - 在
Filter
文本框中输入pom
- 选择
org.codehaus.mojo.archetypes:pom-root:1.1
- 单击下一步并输入所需信息,以便完成父创建。
Create the child project
创建子项目
- Right click at the parent project and select
New ---> Other
. - At the
Select Wizard Windows
, selectMaven ---> Project
.
- At the
- Click next and enter the required information so that we are at the
New Maven Project
. - You will see that the
Parent Project
=MY PARENT
- Enter the
Module name
, e.g. my-ear, my-ejb or my-web. Then clickNext
button, - At the
Filter
textbox, enter some of the followingorg.codehaus.mojo.archetypes:webapp-javaee6:1.5
org.codehaus.mojo.archetypes:ejb-javaee6:1.5
org.codehaus.mojo.archetypes:ear-javaee6:1.5
- Click next and enter the required information so that the child creation is finished.
- 右键单击父项目并选择
New ---> Other
。 - 在 处
Select Wizard Windows
,选择Maven ---> Project
。
- 在 处
- 单击下一步并输入所需信息,以便我们在
New Maven Project
. - 你会看到
Parent Project
=MY PARENT
- 输入
Module name
,例如 my-ear、my-ejb 或 my-web。然后点击Next
按钮, - 在
Filter
文本框中,输入以下一些内容org.codehaus.mojo.archetypes:webapp-javaee6:1.5
org.codehaus.mojo.archetypes:ejb-javaee6:1.5
org.codehaus.mojo.archetypes:ear-javaee6:1.5
- 单击下一步并输入所需信息,以便完成子创建。
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.
这样它会自动将其识别为父项目的子项目。