我应该如何与EGit一起使用多模块Maven项目? [英] How am I supposed to work with multi-module Maven projects with EGit?

查看:144
本文介绍了我应该如何与EGit一起使用多模块Maven项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尽力得到一个使用EGit与GitHub同步的多模块Maven项目,但是我失败了。



项目的结构就像这样:




  • 父(pom)

  • child-one(jar)

  • child-two(jar)



我尝试过这种简单的方法:


  1. 完全空白的Eclipse JDT副本和一个空的工作空间

  2. 创建一个新的GitHub仓库,并使用 README进行初始化.md 文件

  3. 将存储库克隆到Eclipse

  4. 创建父(pom)项目

  5. 创建两个子项目(jar)项目,添加简单的主类,这一切都有效。

部分。我只分享我的父项目吗?还是孩子呢?那么,我只能分享父母似乎是合乎逻辑的。但是当我这样做的时候,我的构建路径变得非常疯狂,Eclipse不再能找到主要类。然后我重新启动了Eclipse。问题持续存在然后我用资料库断开项目,并且逻辑上 EGit随机删除文件系统上的一个子项,并使Eclipse项目完全无法使用(没有类会显示,所有的结构都消失了)。



我以前有一个剧集,EGit随机删除了我的一个存储库,那时候它不只是一个测试,这是我对代码库的实际最新更改。 / p>

这个插件是完全错误的还是我缺少某些东西?



(我按照设置它的基本教程全部,并且我的SSH密钥配置正确。)



我应该如何正确地将本地Maven多模块项目推送到GitHub,并且可以

解决方案

其实100%的可能性这样做



这是一种比以前更简单的方法:


  1. 克隆您的存储库

  2. 创建新的Maven项目时,不要将其放在默认的Workspace位置,将其放在*资源库的子目录**

  3. 完成!您可以创建尽可能多的子模块,Eclipse会自动检测到您的Git存储库。


*当您选择默认位置时,会自动为您创建子目录,并以模块命名。选择不同的位置时自动创建 (这有点不一致,但有意义)。如果您只是选择您的仓库作为您的位置,Eclipse / Maven将生成您的回购根目录中的所有顶级项目文件和目录(pom.xml,.project,src /,.settings,...)目录 - 可能是您想要的,但很可能不是






为了更复杂的解释为什么没有工作,阅读...






这只是一个有点复杂,非常不直观。这是一张如何看待的照片:





我采取的步骤(确保备份任何重要的):


  1. 在GitHub(带README)上创建一个新的存储库

  2. 安装Eclipse JDT(预装了Maven和Egit的Java但它会在我推测的任何Eclipse版本中起作用)

  3. 在Eclipse中克隆资源库。在这个时候,没有项目要导入或任何东西,只有存储库。要克隆,请转到Window - > Open perspective - >其他 - > Git Repository Exploring

  4. 使用Maven在Eclipse中创建项目。我首先创建了一个孩子和一个父母。父母必须有包装类型的pom。孩子可以把它当做一个jar,而且必须是一个Maven 模块,而不是一个项目(但它本质上是一样的)。在这一点上,我在这个子模块中创建了一个简单的主类,并保存了一切

  5. 将您的父项目共享到您之前克隆的存储库(右键单击父 - >团队 - >共享项目 - > Git - >选择您的存储库)。现在,事情会开始分崩离析,但这是正常的。等待Eclipse完成。发生了什么事情是,Eclipse将项目从您之前保存的位置(对我来说是我的工作区)移动到git存储库 - 而且由于父项中有孩子,所以它也移动了它的子存储库。但是,它没有相应地更新其定义,因此子项目现在只显示为空目录。您现在可以提交

  6. 删除缺少的子项目(父项!)

  7. 只需再次导入项目


I tried my best to get a multi-module Maven project synced with GitHub using EGit, but I've failed.

The structure of the project is like this:

  • parent (pom)
  • child-one (jar)
  • child-two (jar)

I tried this simple approach:

  1. Completely blank copy of Eclipse JDT and an empty workspace
  2. Create a new GitHub repository and initialize it with a README.md file
  3. Clone that repository to Eclipse
  4. Create the parent (pom) project
  5. Create two children (jar) projects, add simple main classes, everything works at this point

Now comes the tricky part. Do I share just my parent project? Or children as well? Well, it seemed logical to me to share the parent only. However when I did, my build path went completely crazy and Eclipse could no longer find main classes. Then I restarted Eclipse. Issues persisted. Then I "disconnected" the project with the repository and logically EGit randomly deleted one of the children on the file system, and made the Eclipse project completely unusable (no classes would display, all structure was gone).

I previosly had an episode where EGit randomly deleted one of my repositories and that time it wasn't just a test, it was my actual latest changes to the codebase.

Is this plugging completely bugged out or am I missing something?

(I followed the basic tutorial on setting it all up, and have my SSH keys configured properly.)

What should I do to properly push a local Maven multi-module project to GitHub, and be able to clone it on a completely different PC out of nothing?

解决方案

Actually it's 100% possible to do this!

Here's an even simpler approach approach than before:

  1. Clone your repository
  2. When creating a new Maven project, don't place it in the default Workspace location, place it in the *subdirectory** of the repository
  3. Done! You can create as many sub-modules as you'd like, Eclipse has automatically detected your Git repository.

* the subdirectory is automatically created for you when you choose the default location, and it is named after your module. It's not automatically created when choosing a different location (which is a bit inconsistent, but makes sense). If you just choose your repo as your location, Eclipse/Maven will then generate all the top-level project files and directories (pom.xml, .project, src/, .settings, ...) in your repo's root directory - which might be what you wanted, but most likely isn't.


For a more complicated explanation of why it wasn't working, read on...


It's just a bit complicated and very unintuitive. Here's a picture of how it looks:

Steps I took (make sure to backup anything important):

  1. Create a new repository on GitHub (with README)
  2. Install Eclipse JDT (the "Java" download, with Maven and Egit preinstalled, but it would work in any Eclipse version I presume)
  3. Clone the repository in Eclipse. At this time, there are no projects to import or anything, there's just the repository. To clone, go to Window -> Open perspective -> Other -> Git Repository Exploring
  4. Create your projects in Eclipse using Maven. I first created one child and one parent. The parent has to have packaging type of pom. The child can have it as a jar and has to be a Maven module, not a project (but it's essentially the same thing). At this point I created a simple main class in this child module, and saved everything
  5. Share your parent project to the repository you cloned before (right click on parent -> Team -> Share project -> Git -> select your repository). Now, things will start falling apart, but this is normal. Wait for Eclipse to finish. What happened is that Eclipse moved the project from the place you saved it previously (for me it was my workspace) to the git repository - and since the parent has the children inside it, it also moved the children repositories with it. However, it didn't update its definitions accordingly, so the child project is now just shown as an empty directory. You can commit now
  6. Delete the missing child project (not the parent!)
  7. Just import the projects again

这篇关于我应该如何与EGit一起使用多模块Maven项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆