将 Maven 项目导入 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2061094/
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
Importing Maven project into Eclipse
提问by Thunderhashy
I want to import existing Maven project into Eclipse. I found 2 ways to do it:
我想将现有的 Maven 项目导入 Eclipse。我找到了两种方法:
- Through running from command line
mvn eclipse:eclipse
- To install Maven Eclipse plugin from Eclipse.
- 通过从命令行运行
mvn eclipse:eclipse
- 从 Eclipse 安装 Maven Eclipse 插件。
What is the difference between the both and which one is preferable?
两者之间有什么区别,哪个更可取?
If I install Maven Eclipse plugin through the Eclipse menu Help -> Install New Software, do I still need to modify my pom.xml
to include the Maven Eclipse plugin in the plugins section?
如果我通过 Eclipse 菜单Help -> Install New Software安装 Maven Eclipse 插件,我是否还需要修改我的pom.xml
以在插件部分包含 Maven Eclipse 插件?
采纳答案by Pascal Thivent
I want to import existing maven project into eclipse. I found 2 ways to do it, one is through running from command line
mvn eclipse:eclipse
and another is to install maven eclipse plugin from eclipse. What is the difference between the both and which one is preferable?
我想将现有的 Maven 项目导入到 Eclipse 中。我找到了两种方法,一种是通过命令行运行
mvn eclipse:eclipse
,另一种是从 eclipse 安装 maven eclipse 插件。两者之间有什么区别,哪个更可取?
The maven-eclipse-pluginis a Maven pluginand has alwaysbeen there (one of the first plugin available with Maven 1, one of the first plugin migrated to Maven 2). It has been during a long time the only decent way to integrateimport an existing maven project with Eclipse. Actually, it doesn't provide real integration, it just generates the .project
and .classpath
files (it has also WTP support) from a Maven project. I've used this plugin during yearsand was very happy with it (and very unsatisfied at this time by Eclipse plugins for Maven like m2eclipse).
的Maven的Eclipse的插件是一个Maven插件并总是一直存在(可与Maven 1,迁移到Maven 2的第一插件中的一个第一插件中的一个)。长期以来,它一直是将导入现有 Maven 项目与 Eclipse集成的唯一合适方式。实际上,它不提供真正的集成,它只是从 Maven 项目生成.project
和.classpath
文件(它还支持 WTP)。多年来我一直在使用这个插件并且对它非常满意(并且此时对于 Maven 的 Eclipse 插件如m2eclipse非常不满意)。
The m2eclipseplugin is one of the Eclipse plugins for Maven. It's actually the first and most mature of the projects aimed at integrating Maven within the Eclipse IDE (this has not always been the case, it was not really usable ~2 years ago, see the feedback in Mevenide vs. M2Eclipse, Q for Eclipse/IAM). But, even if I do not use things like creating a Maven project from Eclipse or the POM editor or other fancy wizards, I have to say that this plugin is now totally usable, provides very smooth integration, has nice features... In other words, I finally switched to it :) I'd now recommend it to any user (advanced or beginners).
该m2eclipse的插件是一个Eclipse插件Maven的。它实际上是旨在将 Maven 集成到 Eclipse IDE 中的第一个也是最成熟的项目(情况并非总是如此,它在大约 2 年前并不真正可用,请参阅Mevenide vs. M2Eclipse,Q for Eclipse/ IAM)。但是,即使我不使用从 Eclipse 或 POM 编辑器或其他花哨的向导创建 Maven 项目之类的东西,我不得不说这个插件现在完全可用,提供非常流畅的集成,具有很好的功能......在其他话说,我终于改用它了 :) 我现在将它推荐给任何用户(高级或初学者)。
If I install maven eclipse plugin through the eclipse menu Help -> Install New Software, do I still need to modify my pom.xml to include the maven eclipse plugin in the plugins section?
如果我通过 eclipse 菜单 Help -> Install New Software 安装 maven eclipse 插件,是否还需要修改我的 pom.xml 以在插件部分包含 maven eclipse 插件?
This question is a bit confusing but the answer is no. With the m2eclipse plugin installed, just right-clickthe package explorer and Import... > Maven projectsto import an existing maven project into Eclipse.
这个问题有点令人困惑,但答案是否定的。安装 m2eclipse 插件后,只需右键单击包资源管理器并导入...> Maven 项目,即可将现有的 Maven 项目导入 Eclipse。
回答by Chris Magnuson
I am not experienced with Eclipse or Maven so the other answers seemed a bit over complicated.
我对 Eclipse 或 Maven 没有经验,所以其他答案似乎有点过于复杂。
The following simpler set of steps worked for me:
以下更简单的一组步骤对我有用:
Prerequisite: Make sure you have Maven plugin installed in your Eclipse IDE: How to add Maven plugin to Eclipse
先决条件:确保在 Eclipse IDE 中安装了 Maven 插件:如何将 Maven 插件添加到 Eclipse
- Open Eclipse
- Click File> Import
- Type Mavenin the search box under Select an import source:
- Select Existing Maven Projects
- Click Next
- Click Browseand select the folder that is the root of the Maven project (probably contains the
pom.xml
file) - Click Next
- Click Finish
- 打开日食
- 单击文件>导入
- 在选择导入源下的搜索框中键入Maven :
- 选择现有的 Maven 项目
- 单击下一步
- 单击浏览并选择作为 Maven 项目根目录的文件夹(可能包含该
pom.xml
文件) - 单击下一步
- 单击完成
回答by Morteza Shahriari Nia
Using mvn eclipse:eclipse
will just generate general eclipse configuration files, this is fine if you have a simple project; but in case of a web-based project such as servlet/jsp you need to manually add Java EE features to eclipse (WTP).
usingmvn eclipse:eclipse
只会生成通用的 eclipse 配置文件,如果你有一个简单的项目,这很好;但是对于基于 Web 的项目,例如 servlet/jsp,您需要手动将 Java EE 功能添加到 eclipse (WTP)。
To make the project runnable via eclipse servers portion, Configure Apache for Eclipse: Download and unzip Apache Tomcat somewhere. In Eclipse Windows -> Preferences -> Servers -> Runtime Environments add (Create local server), select your version of Tomcat, Next, Browse to the directory of the Tomcat you unzipped, click Finish.
要使项目可通过 Eclipse 服务器部分运行,请为 Eclipse 配置 Apache:下载 Apache Tomcat 并将其解压缩到某处。在Eclipse Windows -> Preferences -> Servers -> Runtime Environments 添加(创建本地服务器),选择你的Tomcat版本,然后浏览到你解压的Tomcat目录,点击Finish。
Window -> Show View -> Servers Add the project to the server list
Window -> Show View -> Servers 将项目添加到服务器列表
回答by Midnik47
Maven have a Eclipse plugin and Eclipse have a Maven plugin we are going to discus those things.when we using maven with those command line stuffs and etc when we are going through eclipse we don't want to that command line codes it have very much helpful, Maven and eclipse giving good integration ,they will work very well together thanks for that plugins
Maven 有一个 Eclipse 插件,而 Eclipse 有一个 Maven 插件,我们将讨论这些事情。当我们将 Maven 与那些命令行东西一起使用时,当我们通过 Eclipse 时,我们不希望它有很多命令行代码很有帮助,Maven 和 Eclipse 提供了良好的集成,感谢这些插件,它们可以很好地协同工作
Step 1: Go to the maven project. Here my project is FirstApp.(Example my project is FirstApp)
步骤1:转到maven项目。这里我的项目是 FirstApp。(例如我的项目是 FirstApp)
There you can see one pom.xml file, now what we want is to generate an eclipse project using that pom.xml.
在那里你可以看到一个 pom.xml 文件,现在我们想要使用那个 pom.xml 生成一个 eclipse 项目。
Step 2: Use mvn eclipse:eclipse command
第 2 步:使用 mvn eclipse:eclipse 命令
Step 3: Verify the project
第 3 步:验证项目
after execution of this command notice that two new files have been created
执行此命令后,注意创建了两个新文件
Note:- both these files are created for Eclipse. When you open those files you will notice a "M2_REPO" class variable is generate. You want to add that class path in eclipse, otherwise eclipse will show a error.
注意:- 这两个文件都是为 Eclipse 创建的。当您打开这些文件时,您会注意到生成了一个“M2_REPO”类变量。你要在eclipse中添加那个类路径,否则eclipse会报错。
Step 4: Importing eclipse project
第四步:导入eclipse项目
File -> Import -> General -> Existing Projects in Workspace -> Select root directory -> Done
文件 -> 导入 -> 常规 -> 工作区中的现有项目 -> 选择根目录 -> 完成
回答by Taylor Leese
回答by anas
I was unable to import a Maven project with the steps suggested above until I figured out why it was not importing:
我无法使用上面建议的步骤导入 Maven 项目,直到我弄清楚为什么它没有导入:
A maven project will not import if you have another Maven project with the same artifact id. Make sure that your project's artifact ID is unique in your eclipse workspace.
如果您有另一个具有相同工件 ID 的 Maven 项目,则不会导入 Maven 项目。确保您的项目的工件 ID 在您的 eclipse 工作区中是唯一的。
回答by howlger
Since Eclipse Neon which contains Eclipse Maven Integration (m2e) 1.7, the preferred way is one of the following ways:
由于包含 Eclipse Maven Integration (m2e) 1.7 的 Eclipse Neon,首选方式是以下方式之一:
- File > Projects from File System...- This works for Eclipse projects (containing the file
.project
) as well as for non-Eclipse projects that only contain the filepom.xml
. - If importing from a Git repository, in the Git Repositoriesview right-clickthe repository node, one folder or multiple selected folders in the Working Treeand choose Import Projects.... This opens the same dialog, but you don't have to select the directory.
- 文件 > 来自文件系统的项目...- 这适用于 Eclipse 项目(包含文件
.project
)以及仅包含文件的非 Eclipse 项目pom.xml
。 - 如果从一个Git仓库进口,在Git仓库视图中右键单击库节点,一个文件夹或多个文件夹,选择在工作树,并选择导入项目...。这将打开相同的对话框,但您不必选择目录。
回答by Shiwani Bhatt
File ? Import ? Maven ? Existing Maven Project ? Next
文件 ?进口 ?马文?现有的 Maven 项目?下一个
http://www.websparrow.org/misc/how-to-import-maven-project-in-eclipse
http://www.websparrow.org/misc/how-to-import-maven-project-in-eclipse