Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Mercurial, Maven and Eclipse together?

I am currently working on a Java project within a team of 5 colleagues for university. Actually, we will finish the planning phase within the next few days and then start implementing.

For the project, we have to use Mercurial (via Bitbucket.org) and Apache Maven. We'd like to use Eclipse as IDE. I know how to use Mercurial, and I've read some articles and guides about Maven. The thing I don't understand is how we should use those tools in collaboration.

What should be placed on the repository? The whole Eclipse project? Or just the source files and Maven's pom.xml? If the latter, how would a working session look like? Pull the files, create an Eclipse project with mvn eclipse:eclipse, code a while and commit/push them to the repo?

I am responsible for creating the project structure, so my colleagues - and me too - can start developing. But I really don't know how to start now. If the use of Maven wasn't obligatory, I would just place the Eclipse project into the repository. But having to use it, I'm quite confused now how if affects everything.

like image 272
flog Avatar asked Apr 15 '11 11:04

flog


People also ask

Do we need to install Maven separately for Eclipse?

You can Launch Maven builds from within Eclipse. It does the dependency management for Eclipse build path based on Maven's pom. xml. It resolves Maven dependencies from the Eclipse workspace without installing to local Maven repository (requires dependency project be in same workspace).

How do I run a Maven project in Eclipse?

Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button.

Does Eclipse come with Maven?

Eclipse IDE comes with a Maven plugin (called m2e) already installed. We will use this plugin to work with Maven. You are of course free to also install the Maven command line tools, but we won't be using those directly in this tutorial.


1 Answers

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.

like image 139
moritz Avatar answered Sep 18 '22 23:09

moritz