Friday May 23, 2008

10 Steps to Happiness with Maven and the NetBeans Platform

If you're interested in Maven and NetBeans IDE, you should definitely read Best Practices for Apache Maven in NetBeans 6.x, by Milos Kleint, the developer of Maven support in NetBeans IDE. There is an incredible amount of tips and tricks in there, from getting started, to deployment, to optimizing your editing experience. It is probably the most important document you will ever find on Maven and NetBeans IDE. Another crucial article is NetBeans Platform Development with Maven 2 by Emilian Bold, although the archetypes used in this blog entry did not exist at the time that Emilian wrote that article. However, everything in that article is of vital importance to you if you are using Maven to create your NetBeans Platform application/s.

Now let's create our first NetBeans Platform application via the tailor-made NetBeans Platform Maven archetype provided by the NetBeans Maven plugin for NetBeans IDE 6.1.

  1. Start NetBeans IDE 6.1 and install the Maven plugin (Tools | Plugins | Available Plugins).

  2. Go to the New Project wizard (Ctrl-Shift-N) and choose Maven | Maven Project and then click Next.

  3. Choose "Maven Netbeans Platform Application Archetype":

    Click Next.

  4. Very important: Don't forget to fill out the details at the bottom of the dialog:

    The 'brandingtoken' and the 'cluster' could be set to anything. The 'brandingtoken' is used during the customization phase of your application, i.e., to distinguish it from other applications. You need to set this here so that you're aware of what the token is later. However, this will not be very important to you (at all) in the greater part of your development process. The 'cluser' determines the name of the folder that will contain your custom modules, i.e., those that are in addition to the clusters of modules provided by the NetBeans Platform. Again, the cluster name is not very important and can be modified later anyway.

    The 'netbeans-install' field is very important. Later, when you run the application, the application will need to know the location of a NetBeans installation. Above, I have set "/home/geertjan/netbeans-6.1" because that is the top level folder of my NetBeans installation.

    Make sure that you press Enter for each of the fields, otherwise the entered text wont't "take" and the wizard will assume that the field is empty, causing problems later when you try to deploy it. There should be default values for all of the above fields; this is a known problem and will be fixed at some point.

  5. Click Finish and observe the two projects in the Projects window. The first is for the application and the second for a dummy module. You can use that module as your starting point and then add more as needed. Here's what you should see:

    There's one small yet very important thing that should be tweaked (again, a known problem). Open the profiles.xml file that you see above. In there, you'll see an element named "":

    Change that element name to "netbeans.installation". It is a known bug.

  6. Right-click the application and choose Build. It is very important that you do this, because the Run action won't do it for you, so that you'll have deployment problems in the next step if you haven't built the application first.

  7. Now right-click the application and choose Run. This will run the application and you'll see the splash screen of NetBeans IDE 6.1 and then your new application:

    Now, even though our first module doesn't do anything yet, we'll add a second module to our application. To do this, we will need to create our new module in the same folder as where the application is found. Look at step 4 above and notice that we will need to create our new module in "/home/geertjan/NetBeansProjects/DemoRCPApp". OK, let's do it via a new archetype in the next step.

  8. Press Ctrl-Shift-N again and choose Maven | Maven Project | Maven NetBeans Module Archetype:

    Click Next.

  9. Specify the location of the application, as pointed out above:

  10. Click Finish and now you can see that your application consists of two modules (in addition to the modules that the NetBeans Platform makes available):

Now refer to the two articles at the start of this blog entry which, together, should give you everything you need when working with Maven and the NetBeans Platform.


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.


« May 2008 »