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.)
NetBeans Maven Java ( Oct 13 2005, 03:57:40 PM CEST ) Permalink Comments [0]


