X

Geertjan's Blog

  • January 22, 2010

Using Annotations in Mavenized NetBeans Platform Applications

Geertjan Wielenga
Product Manager
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:
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>nbm-maven-plugin</artifactId>
    <version>3.1</version>
    <extensions>true</extensions>
    <configuration>
    <descriptor>src/main/nbm/module.xml</descriptor>
    <brandingToken>${brandingToken}</brandingToken>
    <cluster>foobar</cluster><publicPackages>
    <publicPackage>com.editor.interface</publicPackage>
    </publicPackages>

    </configuration>
    </plugin>

    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:
    <repository>
    <id>plexus-snapshots</id>
    <url>http://oss.repository.sonatype.org/content/repositories/plexus-snapshots</url>
    <name>Plexus Snapshots</name>
    </repository>

  3. Then redefine the "maven-compiler-plugin" as follows, as stated in Milos' blog, again in the container's pom.xml file:
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.1</version>
    <configuration>
    <source>1.6</source>
    <target>1.6</target>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>org.codehaus.plexus</groupId>
    <artifactId>plexus-compiler-javac</artifactId>
    <version>1.7-SNAPSHOT</version>
    </dependency>
    <dependency>
    <groupId>org.codehaus.plexus</groupId>
    <artifactId>plexus-compiler-api</artifactId>
    <version>1.7-SNAPSHOT</version>
    </dependency>
    </dependencies>
    </plugin>

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.

Join the discussion

Comments ( 3 )
  • Fabrizio Giudici Friday, January 22, 2010

    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 http://jira.codehaus.org/browse/MCOMPILER-98 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?


  • Fabrizio Giudici Friday, January 22, 2010

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

    <plugin>

    <artifactId>maven-compiler-plugin</artifactId>

    <configuration>

    <debug>true</debug>

    <optimize>true</optimize>

    <source>1.6</source>

    <target>1.6</target>

    <showDeprecation>true</showDeprecation>

    <showWarnings>true</showWarnings>

    <!-- Workaround for http://jira.codehaus.org/browse/MCOMPILER-98 -->

    <compilerArguments>

    <sourcepath>${project.basedir}/src/main/java</sourcepath>

    </compilerArguments>

    </configuration>

    </plugin>

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


  • Javier Ortiz Tuesday, August 14, 2012

    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?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.