How to use Mercurial, Maven and Eclipse together?

吃可爱长大的小学妹 提交于 2019-12-03 08:29:53
moritz

I use a similar setup, except I am using Dropbox for my repository (just two developers). Just follow these steps, with the m2eclipse (update site: http://m2eclipse.sonatype.org/sites/m2e) and the MercurialEclipse (update site: http://cbes.javaforge.com/update) plugin you can do all in eclipse.

Create a maven project:

File -> New -> Other -> Maven project

In Project explorer right click on the new created maven project

Team -> Share Project... -> Mercurial -> (leave the folder as it is) Finish

Then create an .hgignore file in the project root:

In Project explorer right click on the new created maven project

New -> File -> File Name: .hgignore and Finish

.hgignore:

syntax: regexp
target      # maven output
\.classpath # eclipse
\.project   # eclipse
\.settings  # eclipse
test-output # eclipse junit/testng plugin output

Then you can make your first commit, but beware, hg does not store empty folders in it's repository, so to keep the maven folder structure with no source code in it you have to put a (empty) file in each empty folder, for a simple maven project without any sources it would be in the folders:

  • myproject/src/main/java
  • myproject/src/main/resources
  • myproject/src/test/java
  • myproject/src/test/resources

For example I put a file with the name .empty in it with the content "this is a placeholder file, remove if other files are in this folder"

If some of this folders are missing your colleagues would see errors in eclipse if they import your project.

First commit:

In Project explorer right click on the new created maven project

Team -> Commit... -> Select all and enter a commit message -> Finish

Now you can clone it to bitbucket (I don't have experience with bitbucket).

Tell your colleagues to install the two eclipse plugins and then they can get the repo via

File -> New -> Other -> Check out Maven Project from SCM -> enter url to your repo -> Finish

And then you are good to go.

Here are alternatives based on practices at the ASF (though we don't use Mercurial).

To begin with, set up a source tree with Maven build that you check into Hg. Don't touch eclipse yet. You'll want to find some Eclipse plugin for Hg.

Then, look at two alternatives: the maven-eclipse-plugin and M2eclipse.

The maven-eclipse-plugin is a maven plugin. You run it from command line, and it generates .project and .classpath and some of .settings. It's not currently being worked on, but it's quite stable and functional in many common cases. You then import 'existing Eclipse project' and you are good to go.

M2Eclipse is an Eclipse plugin that integrates Maven builds. It's quite ambitious. However, it's current avatar is quite new, and can be full of surprises.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!