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:
    <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.

Comments:

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?

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:

<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

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
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today