Using Annotations in Mavenized NetBeans Platform Applications

Via Milos Kleint's blog yesterday I learned about the brand new possibility of using annotations in NetBeans Platform applications driven by Maven. That means that the NetBeans Platform Quick Start can now work under Maven.

Here are some things to note, when converting from the above Ant-based tutorial to Maven:

  1. Declare packages as public like this, in the definition of "nbm-maven-plugin" in the pom.xml file of the module where the class is defined:

    More details on NetBeans-specific Maven tags by Fabrizio here. You can also use the asterisk, as described here to also set all subpackages as public to the whole application.

  2. Add the Plexus repository to the "repositories" element of the container's pom.xml file:
        <name>Plexus Snapshots</name>

  3. Then redefine the "maven-compiler-plugin" as follows, as stated in Milos' blog, again in the container's pom.xml file:

And now you're done. The rest of the quick start is the same as in the Ant-based version. The META-INF/services folder will be created thanks to the @ServiceProvider annotation and you'll be able to use Lookup to get hold of the implementation automatically registered there when the application is compiled.


I'd like to start using annotations, but I'm a bit wary on using the snapshot plexus compiler...

Looking at the cited compiler plugin bug I see a comment by Jesse, that with a bit of extra configuration for the plugin compiler could work around the problem. Did anybody tried it?

Posted by Fabrizio Giudici on January 21, 2010 at 11:44 PM PST #

I've found the time to try by myself - yes, it works. My configuration is:

<!-- Workaround for -->

and what you need is the compilerArgument section. I'm using maven-compiler-plugin v2.0.2

Posted by Fabrizio Giudici on January 22, 2010 at 03:01 AM PST #

This seems to no longer work. The plexus libraries are now in the main maven repo so there's no need to add the repository (it doesn't exist any more, at least at that address).I also tried the workaround on the comments without luck. Any updates on how to do this?

Posted by Javier Ortiz on August 14, 2012 at 06:38 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014