将 Maven 项目从 Git 导入 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4869815/
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 a Maven project into Eclipse from Git
提问by Arthur Ulfeldt
How can I get the effect of choosing to import from both Maven and Git and have Eclipse properly generate my project?
如何获得选择从 Maven 和 Git 导入并让 Eclipse 正确生成我的项目的效果?
To get my project into Eclipse I can choose File->import->maven and then I get all the Maven projects imported and can build fine, or I can choose File->import->git and make a new project that ignores the pom.xml and does not generate the project properly.
为了让我的项目进入 Eclipse,我可以选择 File->import->maven 然后我导入所有 Maven 项目并且可以正常构建,或者我可以选择 File->import->git 并创建一个忽略 pom 的新项目.xml 并且没有正确生成项目。
It seems I can do one or the other but not combine both so I get a correctly generated project.
似乎我可以做一个或另一个,但不能将两者结合起来,所以我得到了一个正确生成的项目。
回答by Sri Sankaran
Eclipse Indigo + M2Eclipse 1.0 makes it very easy.
Eclipse Indigo + M2Eclipse 1.0 使它变得非常容易。
If you don't already have the Git connector for M2Eclipse install it. M2Eclipse will help you along by prompting you on the Import menu.
如果您还没有 M2Eclipse 的 Git 连接器,请安装它。M2Eclipse 将通过在导入菜单上提示您来帮助您。
- Select the "Import..." context menu from the Package Explorer view
- Select "Check out Maven projects from SCM" option under the Maven category
- On the window that is presented choose the link "Find more SCM connectors in the m2e Marketplace
- Find connector for Git...install...restart
- 从 Package Explorer 视图中选择“Import...”上下文菜单
- 在 Maven 类别下选择“Check out Maven projects from SCM”选项
- 在出现的窗口中,选择链接“在 m2e 市场中查找更多 SCM 连接器
- 查找 Git 的连接器...安装...重新启动
Note that in the search box you may have to enter "EGit" instead of "Git" to find the right connector.
请注意,在搜索框中您可能需要输入“EGit”而不是“Git”才能找到正确的连接器。
With that done, simply go to the EGit repository, bring up the context menu for the Working directory and select "Import Maven projects...".
完成后,只需转到 EGit 存储库,打开工作目录的上下文菜单并选择“导入 Maven 项目...”。
Done!
完毕!
回答by joelittlejohn
I would perform a git clone via the command line (outside Eclipse) then use File -> Import... -> Existing Maven Projects.
我将通过命令行(在 Eclipse 之外)执行 git clone,然后使用File -> Import... -> Existing Maven Projects。
Your projects will be understood as using Git and Maven. It's the fastest and most reliable way to import IMO.
您的项目将被理解为使用 Git 和 Maven。这是导入 IMO 的最快、最可靠的方式。
回答by Tharindu Rajarathna
Step 1 : Setting Up Eclipse
第 1 步:设置 Eclipse
First of all you'll need to have a few Eclipse plug-ins installed. So use eclipse IDE software install feature in the help dropdown menu → Install new software, and add link to Available Software Site, then install it.
首先,您需要安装一些 Eclipse 插件。所以使用帮助下拉菜单中的eclipse IDE软件安装功能→安装新软件,并添加到可用软件站点的链接,然后安装它。
- GIT plugin (EGIT)- http://download.eclipse.org/egit/updates
- Eclipse Maven plugin (M2Eclipse) - http://download.eclipse.org/technology/m2e/releases
- Maven SCM Handler for EGit (m2e-egit)
Install from the M2E Marketplace (Settings → Maven → Discovery → Open Catalog and search for " m2e-egit")
- GIT 插件 (EGIT) - http://download.eclipse.org/egit/updates
- Eclipse Maven 插件 (M2Eclipse) - http://download.eclipse.org/technology/m2e/releases
- 用于 EGit (m2e-egit) 的 Maven SCM 处理程序
从 M2E 市场安装(设置 → Maven → 发现 → 打开目录并搜索“ m2e-egit”)
Step 2 : Clone the repository
第 2 步:克隆存储库
Clone(download) your Maven Projects from Git
从 Git 克隆(下载)您的 Maven 项目
Check out non-eclipse Maven Projects from Git (File → Import.. → Maven → Check out Maven Projects from SCM)
从 Git 中查看非 Eclipse Maven 项目(文件 → 导入 .. → Maven → 从 SCM 中查看 Maven 项目)
Now add your git repository link to SCM URI field.Then click next & finish.
现在将您的 git 存储库链接添加到 SCM URI 字段。然后单击下一步并完成。
回答by Luca Geretti
As of this (updated) writing, a working setup is the following:
在撰写此(更新)时,工作设置如下:
- Eclipse 3.8 (Eclipse Indigo update site)
- EGit 1.3.0 (Eclipse Indigo update site)
- m2e 1.0.200 (Eclipse Indigo update site)
- m2e-egit 0.14.0 (m2e marketplace when adding a connector)
- Eclipse 3.8(Eclipse Indigo 更新站点)
- EGit 1.3.0(Eclipse Indigo 更新站点)
- m2e 1.0.200(Eclipse Indigo 更新站点)
- m2e-egit 0.14.0(添加连接器时的 m2e 市场)
Tested on Ubuntu Raring.
在 Ubuntu Raring 上测试。
You can certainly "Import" -> "Maven" -> "Check out Maven Projects from SCM", and this is the quickest way. However, such direct import currently does not give you control over the cloned repository folder name. You may be better off working from the "Git Repository" View and perform either a "Clone from a Git Repository and add the clone to this view", followed by an "Import Maven Projects" from such clone; the longest way would be to do your manual cloning and then "Add an existing local Git Repository to this view", followed again by an "Import Maven Projects". Either case you have full control on the cloned folder.
您当然可以“导入”->“Maven”->“从 SCM 中查看 Maven 项目”,这是最快的方法。但是,这种直接导入目前无法让您控制克隆的存储库文件夹名称。您最好从“Git Repository”视图工作并执行“从 Git 存储库克隆并将克隆添加到此视图”,然后从此类克隆执行“导入 Maven 项目”;最长的方法是进行手动克隆,然后“将现有的本地 Git 存储库添加到此视图”,然后再次“导入 Maven 项目”。无论哪种情况,您都可以完全控制克隆的文件夹。
A final comment on a side issue that made me cry in frustration. As far as I know, if the cloned repository lies on the root of your Eclipse workspace, and your Maven project file hierarchy has a POM on its root, then importing such root project will rename the cloned folder (with the template you chose, defaults to [artifactId]). Without changing your project structure and without keeping files outside your workspace, you can easily work around this issue by cloning on a subsubfolder of the workspace folder.
关于一个让我沮丧地哭泣的附带问题的最后评论。据我所知,如果克隆的存储库位于您的 Eclipse 工作区的根目录,并且您的 Maven 项目文件层次结构在其根目录上有一个 POM,那么导入这样的根项目将重命名克隆的文件夹(使用您选择的模板,默认值)到 [artifactId])。无需更改项目结构,也无需将文件保留在工作区之外,您可以通过克隆工作区文件夹的子文件夹轻松解决此问题。
回答by simbo1905
I have been testing this out for my project.
我一直在为我的项目测试这个。
- Eclispe Indigo
- "Help > Install New Software" Enable/Install official Git plug-ins at "Eclipse Git Plugin .." and install the lot.
- Enable the Maven/EGit connector with these instructions How do you get git integration working with m2eclipse?
- Switch to the Git Repository perspective. Right click paste the project git url. The defaults should all work. You may want to change the install folder it guesses.
- Expand the cloned repository and right click on "Working Tree" and pick "Import Maven Projects...".
- Switch to the Java perspective. Right click on the project and choose "Team > Share Project". Select "Git" and be sure to tick the box "Use or create repository in parent folder of project".
- Eclispe 靛蓝
- “帮助 > 安装新软件”在“Eclipse Git Plugin ..”启用/安装官方 Git 插件并安装。
- 使用这些说明启用 Maven/EGit 连接器如何使用 m2eclipse 进行 git 集成?
- 切换到 Git 存储库透视图。右键单击粘贴项目 git url。默认值应该都有效。您可能想要更改它猜测的安装文件夹。
- 展开克隆的存储库并右键单击“工作树”并选择“导入 Maven 项目...”。
- 切换到 Java 透视图。右键单击项目并选择“团队 > 共享项目”。选择“Git”并确保勾选“在项目的父文件夹中使用或创建存储库”框。
回答by Arlo
Here's my workaround, this is a solution to these issues:
这是我的解决方法,这是解决这些问题的方法:
- You can't install m2e-egit (I get an error in Juno)
- Converting a general project (connected to your Git repository) to a Maven project isn't working for you (The Import Maven Projects step seems essential)
- Importing Maven Projects from your repository on the filesystem isn't showing the project connected to Git.
- 您无法安装 m2e-egit(我在 Juno 中出现错误)
- 将一般项目(连接到您的 Git 存储库)转换为 Maven 项目对您不起作用(导入 Maven 项目步骤似乎必不可少)
- 从文件系统上的存储库导入 Maven 项目不会显示连接到 Git 的项目。
- Setup your Git repository in the Git Repository Exploringperspective.
- Switch to the Java perspective, Import > Existing Maven Projects
- Browse to your Git checkout in the filesystem, select the directory containing the pom.xml file. Finish the import; you'll notice these projects aren't connected to Git. :-(
- Delete these projects, but DO NOT DELETE FROM FILESYSTEM. We don't want our clone deleted; this task also leaves the .project file behind so that we can import in the next step.
- Go back to the Git Repository Exploringperspective.
- Right-click your repository, Import Projects...
- Select Import existing projects
- In the explorer below, browse to and select the directory containing the pom.xml (and .project file) , then click next.
- Continue through the wizard.
- 在Git Repository Exploring透视图中设置您的 Git 存储库。
- 切换到 Java 透视图,Import > Existing Maven Projects
- 浏览到文件系统中的 Git checkout,选择包含 pom.xml 文件的目录。完成导入;你会注意到这些项目没有连接到 Git。:-(
- 删除这些项目,但不要从 FILESYSTEM 中删除。我们不希望我们的克隆被删除;此任务还将 .project 文件留在后面,以便我们可以在下一步中导入。
- 回到Git Repository Exploring透视图。
- 右键单击您的存储库,导入项目...
- 选择导入现有项目
- 在下面的资源管理器中,浏览并选择包含 pom.xml(和 .project 文件)的目录,然后单击下一步。
- 继续通过向导。
回答by kolobok
Import without installing any additional connectors for Mylyn:
导入而不为 Mylyn 安装任何额外的连接器:
- Open
Git Repositories
view (Window->Show view->Git Repositories) - Press
Clone a Git Repository
button and proceed with all steps - In newly created repository expand
Working Directory
, right click on folder with your project and selectImport Projects
. Then either chooseImport existing projects
, or selectImport as general project
. If needed after importing right click on your project and select Configure->Convert to Maven Project (and Maven->Update Project).
- 打开
Git Repositories
视图(Window->Show view->Git Repositories) - 按下
Clone a Git Repository
按钮并继续所有步骤 - 在新创建的存储库展开中
Working Directory
,右键单击项目所在的文件夹并选择Import Projects
. 然后要么选择Import existing projects
,要么选择Import as general project
。如果需要,在导入后右键单击您的项目并选择配置->转换为 Maven 项目(和 Maven->更新项目)。
回答by Peter H?gg
You should note that putting generated metadata under version control (let it be git or any other scm), is not a very good idea if there are more than one developer working on the codebase. Two developers may have a totally different project or classpath setup. Just as a heads up in case you intends to share the code at some time...
您应该注意,如果有多个开发人员在代码库上工作,将生成的元数据置于版本控制之下(让它是 git 或任何其他 scm)并不是一个好主意。两个开发人员可能有完全不同的项目或类路径设置。以防万一您打算在某个时候共享代码...
回答by Tom Norton
I have a maven project with three submodules that is managed in git. I set them up in eclipse as follows:
我有一个 Maven 项目,其中包含在 git 中管理的三个子模块。我在 eclipse 中设置它们如下:
- I registered the git repository with eclipse using EGit
- I imported the projects as existing Maven Projects
- For each project, I went Team| Share Project.
- 我使用 EGit 向 Eclipse 注册了 git 存储库
- 我将项目作为现有的 Maven 项目导入
- 对于每个项目,我都去了Team| 共享项目。
回答by Randy
After checking out my branch in Egit, I switched to the Java View, then used File-->Import, Git-->Projects from Git, then selected the top level maven directory. This was with Eclipse Kepler.
在 Egit 中检出我的分支后,我切换到 Java View,然后使用 File-->Import,Git-->Projects from Git,然后选择顶级 maven 目录。这是与 Eclipse Kepler 一起使用的。