Friday, November 5, 2010

NetBeans 7.0 M2 and Maven 3 - Better than M2Eclipse?





I've been and am still a happy user of Eclipse since V1.0 - but there is always room for improvement, even in the best tool. And, honestly, the Maven integration is certainly one of the weak spots of Eclipse. M2Eclipse offers a lot of functionality in this area, but it is SLOW. I tried all sorts of tricks to speed things up (some of them I described in this post), but still: it is slow. It is not that slow that one cannot work with it. It is just slow enough to put me in anger from time to time. For example, Eclipse gets sometimes completely stuck. Or it takes several minutes to perform a simple refresh operation. Nothing critical, but anything from smooth ...
I talked to a colleague a while ago and he pointed me to the new M2 of NetBeans 7.0. He told me that it comes with an improved integration of the brand new Maven 3.0. I never used NetBeans before, but the issues with M2Eclipse bother me enough to take a look at it. Here we go:

I freshly installed NetBeans and opened my Maven project. No need for some sort of special import here. I simply choosed File | Open Project and selected the project folder containing the Maven root project. NetBeans even marks all Maven projects in the tree with a special icon.

The import finished amazingly fast. NetBeans analyzed the project structure for while after the import in a background process, but nevertheless I could immediately start to work with my modules.

After the background processes finished, some problems showed up in the project list. NetBeans marks the respective projects with warning and error icons. In the context menu of a project you can click on "Show and resolve problems ..." to open a summary of all problems.

In my case Maven could not find some dependencies in my local repo, which is OK (I did some cleaning up the days before and obviously I was little bit to rigorous). Additionally I was only kind-of online during the tests.

Next, I took a look at the folder structure inside one of the modules. Obviously, NetBeans knows a lot more about Maven projects than Eclipse/M2Eclipse. For example, it knows about generated-sources right out-of-the-box. Even more important, it knows that Maven maintains separate dependencies (and classpaths) for "normal" modules and for tests.

The latter one is in my eyes really important. The Eclipse builders don't distinguish between classpaths for modules and for module tests - regardless if you use Maven/M2Eclipse or not. In consequence, you will regularly run into issues where the Eclipse builder runs flawless, but the Maven build will not. This is just because some of your modules coded in Eclipse reference a dependency with test scope. Eclipse will not recognize this, but Maven will. And NetBeans, too. I like that!

Besides the more or less cosmetic features I was especially interested in how NetBeans performs compared to Eclipse/M2Eclipse. To test this I did some simple refactorings in a central module of one my biggest Maven projects. Since this module is referenced by nearly all other modules, the builder gets a lot of work. In Eclipse this means, that for all dependent modules the M2Eclipse and the internal builder is invoked. This works OK, but again, it is anything from smooth. My first tests in NetBeans have been quite encouraging. First, the refactoring worked nearly as fast as in Eclipse. Second, the build really executed in the background. That is, I was able to continue working during the build. Next, the build completed in seconds, not minutes.

After these basic tests I played with some of the other features. One thing I would like to mention is the dependency graph in NetBeans. It works similar to the one from M2Eclipse, but adds some useful features. For example, it zooms out an artifact and all direct dependents from the graph if you select it (and dims all others). It's hard to explain, but very cool and useful. Try it out yourself!

I also found some features of M2Eclipse that are not supported in NetBeans (at least I didn't find them). There is no such thing as a full-blown POM editor. NetBeans has a POM editor, but it "just" supports editing directly in the XML. The XML editor has a lot of features, like inserting new dependencies using an artifact search. This is perfect for me, since I never used the comprehensive M2Eclipse editors, but I know many people do.

Summary: I am quite impressed about how well-integrated NetBeans 7M2 and Maven 3 are. Both the functionality and especially the performance are in my opinion better than what you currently get with Eclipse and M2Eclipse. But please keep in mind that this only reflects my experiences of a first try. Certainly, if I start working with NetBeans more intense, more problems will arise. And, of course, a new release of M2Eclipse will be out soon, maybe this fixes many of the current issues. But still: I think NetBeans 7 is well worth a try for all developers that rely on Maven as a build system.

16 comments:

  1. Also keep in mind that the m2eclipse plugin has been in a standstill for a while now, because the core team was focused on Maven 3. Now, after Maven 3 has been released, work has restarted on the plugin (announced on their blog and also aparent in JIRA).

    ReplyDelete
  2. What I like in Netbeans is that it fully uses the POM. There are no other configuration files for the project. The result is that it really builds the same with or without NetBeans. Contrary to what you describe with Eclipse. I guess that Eclipse keeps its own project definition files and performs some kind of synchro with the Maven POM ?

    Also Eclipse being the most used IDE, it doesn't need a tools that facilitate switching IDE :-)

    ReplyDelete
  3. Right, Eclipse maintains a separate project config file. M2Eclipse synchronizes it automatically with the POM. If this fails for some reason, you can trigger the synchronization manually. I agree that this approach is more error-prone than using the POM directly (however, it works OK most of the time).

    ReplyDelete
  4. Have you recognized the code completion in the POM yet? Just press Ctrl-Space anywhere in the POM to see it working. It works even within elements, so you can use it to lookup version numbers of your dependencies, etc.

    ReplyDelete
  5. did you ever try intellij idea with maven 2... you should love it more i guess

    ReplyDelete
  6. Another thing I like is the way you can define custom actions in Netbeans that map to specific goals. You can do a similar thing in Eclipse, but, as usual, it is much more cumbersome.

    ReplyDelete
  7. I never tried IntelliJ up to now, maybe I really should take a look at it. Right now I'm working on a Groovy project using NetBeans. I like that, too!

    ReplyDelete
  8. I had some trouble with this version, I did like the integration of the latest maven-3.0, which seems quite stable, however, I build off a drive mapped as B: and repeatedly the build is amazingly slow in this situation. Not so with the 6.9.1 with the maven-3.0.

    ReplyDelete
  9. Certainly, if you start working with NetBeans more intense, more problems will arise. On the other hand you'll also become more proficient with the IDE and find a thousand tricks that will speed up your process.

    At the moment I am trying the opposite, i.e. after almost 10 years (and running) spent on NetBeans I am working on Eclipse for a Naked Object application, and I find it a little more difficult, while on NetBeans almost everything comes smoothly out of the box. Maybe it's just my scarse knowledge of the tool that is hindering me... or is it?

    ReplyDelete
  10. Eclipse builds the .project file using info from the POM when you do 'Import existing Maven project'. So there is no stuff that Eclipse will shove in that prevents you from building the project outside Eclipse. This is unlike what I know about Netbeans Ant build.xml's that Netbeans generates and which require Netbeans to build.

    With some of Eclipse's own configuration it can ensure you can do a lot of stuff from within Eclipse, but it does not impose this upon you.

    Don't know about how Eclipse and Netbeans hold up to each other in terms of performance, but as a whole the performance of Eclipse has improved a lot with Eclipse 3.6.

    ReplyDelete
  11. i'm happy with intellij. x eap maven support signifacantly better.

    ReplyDelete
  12. @Edwin Just a little clarification: ant-based NetBeans projects are indeed able to build without NetBeans, for example just by calling 'ant' on the command line.

    When creating an ant-based NetBeans project, it deploys a whole set of ant .xml files and provides a front-end build XML file so that you can plug at many many build steps to perform your custom operations, if any.

    I think this is a nice feature from NB, though I'm now more into using Maven for our builds, and I find NB's support also quite good (not tested other IDE there, though).

    ReplyDelete
  13. Add jar to Pom:

    Select > Window > Other > Maven Repository

    Do a search, find a jar you need.

    Right click > add as dependency to

    Add Dependency dialog opens and you can select the Maven project required.

    ReplyDelete
  14. Thanks to @gavaroo_99, the tips really help very much!

    ReplyDelete
  15. you have some very good reason but I am not going to abandon Eclipse my favorite IDE :)

    Javin
    10 tips on debugging Java Program in eclipse

    ReplyDelete
  16. Air began to pray earnestly to reach the station soon, because I just no longer subsidized. At one time the train stopped in the midst of nowhere and stopped. климатици

    ReplyDelete

Note: Only a member of this blog may post a comment.