20051013 Thursday October 13, 2005

Maven 2 NetBeans Plugin

One of the things that I hate most about Maven 2 (and that's really all I hate about it: I like it a lot!) is the fact that it has better support for Eclipse than for using NetBeans. Even the earliest Maven 2 distributions (alpha-0?) provided a way to generate the Eclipse project files, using m2 eclipse:eclipse. It's not the full Mevenide support, but it's definitely useful. It sets the paths to external libraries correctly, sets the source and test directories and a couple of other things, and that's really all it takes to get started.)

Today, I crafted my own NetBeans version of a similar Maven plugin. It's fairly simple: you simply type m2 netbeans:netbeans, and it will generate the missing NetBeans project files for your Maven 2 project. I was a little worried that it would be an aweful amount of work, but it really appeared to be quite simple.

So here's an example. In this case, I'm going to generate NetBeans project files for the Maven 2 NetBeans Plugin itself. Here's the POM:

<?xml version="1.0"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-netbeans-plugin</artifactId>
  <version>0.1-SNAPSHOT</version>
  <packaging>maven-plugin</packaging>
  <name>Maven 2 Netbeans Plugin</name>
  <description>
    The NetBeans equivalent of the eclipse:eclipse m2 plugin.
  </description>
  <dependencies>
    <dependency>
      <groupId>antlr</groupId>
      <artifactId>stringtemplate</artifactId>
      <version>2.2</version>
    </dependency>
    <dependency>
      <groupId>plexus</groupId>
      <artifactId>plexus-utils</artifactId>
      <version>1.0.2</version>
    </dependency>
    <dependency>
      <groupId>plexus</groupId>
      <artifactId>plexus-container-default</artifactId>
      <version>1.0-alpha-4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-project</artifactId>
      <version>2.0-alpha-3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0-alpha-3</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
</project>

As you can see, there are alreay a couple of external dependencies listed here, but the number of jar files that need to be included in the NetBeans project is even bigger: almost all of the libraries listed here have dependencies on other libraries as well.

With this pom.xml project file, I'm going to invoke m2 netbeans:netbeans. This is what you get:

[INFO] Searching repository for plugin with prefix: 'netbeans'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven 2 Netbeans Plugin
[INFO]    task-segment: [netbeans:netbeans]
[INFO] ----------------------------------------------------------------------------
[INFO] [netbeans:netbeans]
[INFO] Generating build-impl.xml
[INFO] Generating project.properties
[INFO] Generating project.xml
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Oct 13 16:09:19 CEST 2005
[INFO] Final Memory: 2M/4M
[INFO] ----------------------------------------------------------------------------

After running the plugin, you can open the project in NetBeans, and it will look like the screenshot below. Notice that the source directory has been correctly set, and that all of the dependencies have been resolved to files found in the Maven 2 local repository, so you will have instant code completion.

It appears that building this Maven plugin took only one single source file, of approx. 100 lines of code. The plugin hasn't been submitted to the Maven community so running m2 netbeans:netbeans won't get you anywhere yet. (Normally, you would expect Maven to download and install the plugin automatically. I'll try to carve out some time to get it in the Maven repository.)


( Oct 13 2005, 03:57:40 PM CEST ) Permalink Comments [0]

@JFall

Yesterday, we celebrated Java at the JFall conference in Holland, and I had a great time.

Reunion@JFall

First of all, it was like a big Java geek reunion; I ran into several people from my former lifes at other companies. None of them did Java back then, but they are now all working in the Java space.

Jackpot@JFall

I myself presented Jackpot to quite a big crowd. (It's almost like they hadn't read the warnings and disclaimers in the summary of my presentation. ;-) Jackpot is both a framework for source code transformations and a couple of plugins in NetBeans. It comes with an extremely simple and convenient rules language allowing you to almost script transformations, but behind the scenes it relies heavily on more complex things like the different models that javac builds before turning Java source code into bytecode. So it was quite a relief that - after the talk - I still had everybody in the room.

In fact, they even noticed an erroneous Jackpot rule in one of my slides. ~:^[ And they came up with some interesting suggestions, like using Jackpot to turn untyped collections into typed collections. :^D (Java 1.5)

NetBeans@JFall

After my session, I got to talk to Geertjan Wielenga, part of the NetBeans team and the world's most noticable NetBeans blogger. He showed me how NetBeans 5 allows you to create a new NetBeans module in a blink of an eye, and blew me away completely. I'm telling you, it just can't get any easier than this! This way, even my 5-year old is able to create NetBeans modules. (Is the NetBeans team promoting child labour or something?)


( Oct 13 2005, 10:50:18 AM CEST ) Permalink Comments [0]