开发者

Eclipse Java Projects in Git

I am trying to figure out the best way to create a java project in GIT. In particular I would like to create the git repository such that when I import from git in Eclipse, the project is automatically created correctly with all its .project settings intact and all other settings setup. I.E. if I do a git clone javaEclipseProject in my workspace/ folder then do an import on that javaEclipseProject folder it will open up t开发者_JAVA技巧he project without having to use the new project wizard.


Add the dot-files (.project, .classpath and the .settings directory) to the Git repository. That is what we do with the Git plugin itself.


I'm sure you could do that....but I know even in the company I work for, .project files are not portable from one machine to another. If you get your project building in either Ant or Maven then check it in, Eclipse, Netbeans and/or IntelliJ will be able to check out the project and build their own .project files from your start.

Moving on to the more....shall we say "religious" aspects of the problem, personally I like the way Maven or Ivy or "insert many other Ant++ build tools here" will go ahead and find any dependencies that you might not have already and download them for you. I'm sad to say, but in the times I've used them, Eclipse actually has the least easy to use Maven support though, I don't use IntelliJ, but the snobs.....I mean co-workers I have that do say integration is seamless, and Netbeans it just flawless for Maven.

YMMV of course.


What you could do is to create another branch called eclipse next to your master branch which stores your additional eclipse project files. To do so, you basically need to:

  1. Create a git repository
  2. Stage your files, add a .gitignore with the content of anything from eclipse for e.g. this one, commit everything
  3. Create a new branch called eclipse
  4. Alter your .gitignore file or clear it, so that it will track your additional files
  5. In your project directory execute git config merge.ours.driver true
  6. Still on your eclipse branch, create the file .gitattributes and add this line: .gitignore merge=ours. This will make git always keep the eclipse's branch version of .gitignore when performing a merge.
  7. Stage your .project file its siblings from eclipse together with your newly created .gitattributes
  8. After committing all these things your two branches are "in sync" with the difference that your eclipse branch additionally contains the project configuration files.

Once you make changes to your source files and commited them to your master branch, you can pull these changes over to your eclispe branch by merging it with the --no-ff option. It is important that you never do a fast-forward merge into the eclipse branch when using this method! Also never commit changes on your source files to your eclipse branch directly, always merge them into - this way you will never get merge conflicts and keep your life simple.


I'm not sure if this existed at the time the question was asked, but eclipse now has a new plugin called EGit in which you can import projects from git, commit, push, pull, merge, etc right in eclipse. I just discovered this recently and it's very useful.

If i'm not mistaken, EGit is now built into Eclipse Mars without you needing to add it manually. All of the git functions can be found by right clicking on a project and hovering over the team option. I use it alot wtih Bitbucket

You can find EGit here http://www.eclipse.org/egit/

Eclipse Mars is on the home page http://www.eclipse.org/

Eclipse Java Projects in Git

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜