Hints and tips on using m2eclipse

m2eclipse (http://m2eclipse.codehaus.org/) is an excellent way of combining Maven with Eclipse. We use it in both Naked Objects (http://www.nakedobjects.org) development and I’ve also been using it for the sister Restful Objects (http://restfulobjects.sourceforge.net).


When you invoke a build in Eclipse, m2eclipse “sort of” delegates to the Maven builder. In fact, I am told by Eugene that it still uses Eclipse’s own JDT to do the compilation, but it’s still a pretty good approximation. You can use the Maven console to see what’s going on, and the output (to my eyes at least) is pretty much the same as running Maven from the command line.

If you perform a Maven build (mvn clean install) from the command line, then all modules are picked up from the local repository. m2eclipse sets up the classpath slightly differently so that all Maven modules that are in the workspace are referenced locally, and everything else is picked up from your local repository. In practice this means that you can develop in Eclipse pretty much the same as before.

It is worthwhile performing builds occasionally using Maven command line; there are sometimes slight differences between the Sun javac and Eclipse’s built-in Java compiler. If you do run a command-line build then you must perform a refresh in Eclipse workspace. A project/clean is often required after that.

On occasion I’ve found though that this isn’t enough; m2eclipse thinks that all class files are up-to-date and doesn’t build anything. To force m2eclipse to rebuild everything, the File / Refresh followed by a Project / Update All Maven Dependencies is pretty much guaranteed to do the trick.

Posted on October 6, 2008, in random. Bookmark the permalink. 2 Comments.

  1. Eugene Kuleshov

    Few corrections:* it is m2eclipse, not M2Eclipse* m2eclipse does not exactly delegate build to Maven. Compilation in the IDE is still done by JDT and only resource processing and generation is delegated to Maven (we still have some work to do in that area)* after running Maven from command line you *must* perform refresh in Eclipse workspace and Project / Clean is often required after that.* if your pom.xml does generate resources or java code, it might be necessary to run Maven / Update Project Configuration to add generated source folders to JDT

  2. Thanks, Eugene, original post updated with your comments.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 126 other followers