Thursday Jan 21, 2010

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.

Maven DocCheck Plugin and NetBeans Platform Applications

Yesterday I answered one unanswered question from the Poznan NetBeans Platform Certified Training. Today, another one. It comes from Grzegorz Buszkiewicz who wants to use Maven DocCheck Plugin for a NetBeans Platform application developed in NetBeans IDE.

Here's a rough guide to how I set it up and managed to get it working.

  1. Download (from here) and then unzip the DocCheck doclet JAR.

  2. On the command line, find your way to the directory where you unzipped the above JAR and then run this:
    mvn install:install-file -Dfile=doccheck.jar -DgroupId=com.sun.tools.doclets -DartifactId=doccheck -Dversion=1.2b2 -Dpackaging=jar -DgeneratePom=true

  3. Add the following to the "pom.xml" of the module where you want to apply the DocCheck (or add it to the top level pom.xml to apply it to all modules):
    <project>
    ...
    ...
    ...
        <reporting>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.6.1</version>
                    <reportSets>
                        <reportSet>
                            <id>html</id>
                            <reports>
                                <report>javadoc</report>
                            </reports>
                        </reportSet>
                        <reportSet>
                            <id>doccheck</id>
                            <configuration>
                                <name>DocCheck</name>
                                <description>DocCheck documentation</description>
                                <doclet>com.sun.tools.doclets.doccheck.DocCheck</doclet>
                                <docletArtifact>
                                    <groupId>com.sun.tools.doclets</groupId>
                                    <artifactId>doccheck</artifactId>
                                    <version>1.2b2</version>
                                </docletArtifact>
                                <destDir>doccheck</destDir>
                            </configuration>
                            <reports>
                                <report>javadoc</report>
                            </reports>
                        </reportSet>
                    </reportSets>
                </plugin>
            </plugins>
        </reporting>
      ...
      ...
      ...
    </project>

  4. Now right-click the module and add a new action in the Actions tab. I named it "Reports". Then add "javadoc: javadoc site:site", as shown below:

  5. Now close the above dialog, right-click the module, and choose Custom | Reports and then the above action will be run.

  6. When everything is finished processing, go to the Files window, and you should see a "doccheck" folder containing the generated files:

    Now you'll have useful doc-related info for your code, such as here:

Not sure if all the steps above are needed, or whether it is optimal, but at least it works!

In other news. Read Milos Kleint's blog today to find out how to use NetBeans annotations in Maven-driven NetBeans Platform projects!

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
« January 2010 »
SunMonTueWedThuFriSat
     
2
4
9
10
16
20
22
      
Today