The ability to easily build an update center that users of your application can use to update their software, is a very useful feature of the NetBeans Platform. And being able to build this from the command line means that it can be useful on a build server.

For an Ant-based application, you can call the nbms target in the build script of the suite. The nbms and update.xml file will be built to <suite folder>/build/updates. This can also be executed from the NetBeans IDE by right-clicking on the suite project > Package As > NBMs.

With a Maven-based project, you can use the following command in the parent project folder:

mvn nbm:autoupdate

The nbms and update.xml file will be placed in the parent project folder, under target/netbeans_site.

Everything is subtly (or not so subtly) different between building and running a NetBeans Platform application with Ant and with Maven. When running an application from the IDE, only one instance of the application is allowed to run at a time. The error message displayed when trying to run a second instance with an Ant-based project is clear:

C:\NetBeans\harness\suite.xml:502: The following error occurred while
executing this line:
C:\NetBeans\harness\run.xml:198: The application is already running within
the test user directory.
You must shut it down before trying to run it again.

The Maven one is a little less informative, particularly for Java developers who are not used to building .exes:

Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:3.7:cluster-app
(default-cli) on project test2-app: Cannot process etc folder content
creation. C:\Projects\Tests\test2\application\target\test2\bin\test2.exe
(The process cannot access the file because it is being used by another
process) -> [Help 1]

Hopefully the knowledge that these two things have the same cause will be useful to developers new to developing NetBeans Platform applications with Maven. :)

Today I discovered another great new addition to the latest development builds of the NetBeans IDE: building installers from the IDE for a Maven-based NetBeans Platform application!

I am using NetBeans 7.2 development build 201204150400, but I don’t know exactly when this was introduced. In this development build, I can right-click on the the App project in the Projects view and choose Build Installers. The installers are built to the target folder of the app (the output tells you exactly where the files are generated).

As with Ant-based projects, you can configure which installers get built. For Maven-based platform applications, you will find this configuration in the properties of the App project under the Installer category.

You can also build the installers by calling Maven from the command line:

mvn nbm:build-installers

Have a look at this AgroSense page for related information.

The status bar that appears at the bottom of a NetBeans Platform application can be extended with your own components. When I recently wanted to do this, I searched the Internet for good resources on this topic. And so I found this blog entry by Emilian Bold. It is very useful indeed, but it dates back to before the introduction of the @ServiceProvider annotation. And so I decided to write this article with more up do date information.

Just as Emilian describes, the first step is to create a class that implements StatusLineElementProvider.

import java.awt.Component;
import javax.swing.JLabel;
import org.openide.awt.StatusLineElementProvider;

public class NewStatusLineElement implements StatusLineElementProvider
{
    @Override
    public Component getStatusLineElement()
    {
        return new JLabel("Shalom");
    }
}

This requires a module dependency on the UI Utilities API module.

The difference is that instead of adding an entry to a META-INF/services file, we add the @ServiceProvider annotation to the class:

import java.awt.Component;
import javax.swing.JLabel;
import org.openide.awt.StatusLineElementProvider;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = StatusLineElementProvider.class, position = 100)
public class NewStatusLineElement implements StatusLineElementProvider
{
    @Override
    public Component getStatusLineElement()
    {
        return new JLabel("Shalom");
    }
}

This requires a dependency on the Lookup API module.

One more interesting point. I wanted to add a separator between two of my items, but it just would not appear. And then I realised it might need to have a size specified. So here is the getStatusLineElement() method that successfully adds a separator:

@Override
public Component getStatusLineElement()
{
    JSeparator s = new JSeparator(SwingConstants.VERTICAL);
    s.setPreferredSize(new Dimension(5, 16));
    return s;
}

Every so often I find a corner of the Internet where you can almost see the dust that collected on the servers hosting the venerable pages over the years. And it feels like travelling back in time. :)

Today I had such an experience again. I was reading this page when I clicked on a link to esus.com – a Q&A kind of site. Have a look at the page on JTable to see what I mean. The last date I can see on the site is 2003. And yet it is still there!

I hope to go back in 50 years and find it still running! :D

In the NetBeans 7.2 IDE development builds another cool change is the ability to switch between more than just source files with Ctrl+Tab. For example, now you can switch between source and design views for Swing forms, and to non-source windows. Go ahead, try it out! :-)

I have not forgotten about my series of articles on learning Maven. A new article will be coming soon with some very useful information.

With each new version of the NetBeans Platform, there are useful new features that developers can use in their platform applications. And 7.2 is no exception to this rule. :)

There are a number of new features already available in the development builds for 7.2, in the Window System amongst others. The one feature that has been drawing some attention is the fact that a TopComponent can now have an animated icon indicating to the user that it is busy with some process. What the NewAndNoteworthyNB72 page does not say is how this can be used. In your TopComponent, simply call

makeBusy(true);

to activate the icon. Have a look at the javadoc for more info.

One of the fun things about using the latest development builds of the NetBeans IDE is discovering the small new features that make life easier. And of course letting everybody else know about them. :)

So today I was playing around with the latest development build for 7.2 (build 201203180400) and I found something small but noteworthy. When working with any Java project, you are dealing with source packages in the Projects view. And there are different options for how they are displayed.

This feature was discussed in a very interesting thread on the mailing list back in NetCAT 7.1. If you are interested in reading the discussion (which includes the merits and problems associated with each option), it starts here.

In NetBeans 7.1, there were two options: List view and Tree view. These are accessible by right-clicking on a space in the Projects window and choosing View Java Packages as… from the context menu.

The default view is List. Lets look at what a Java application with a number of source packages looks like in this view.

List View

List View

Only source packages that contain source files are shown.

The other view that has been around for a while is the Tree view. Lets look at the same project, in tree view:

Tree View

Tree View

While this view may be more compact for really big projects, for smaller ones it adds a lot of effort in my opinion when you just want to switch between your packages. And that was my argument for not having the tree view as the default option.

Now if you read the whole mailing list thread, you would have noticed that there was a new option that was proposed: Reduced Tree. And that is now available in the NetBeans 7.2 development builds! :-) So lets have a look at the same project again, in the new view:

Reduced Tree View

Reduced Tree View

This is a brillaint compromise between the two views! Packages with no source files are shown a like they would have been in the list view. And the rest like the tree view. It gives you a quick to navigate view for smaller projects and still keeps the list compact for large projects. Thank you to the NetBeans team for yet another very useful improvement!

There is one bug in the NetBeans IDE that has been my nemesis ever since upgrading to Windows Vista 64-bit back in the day: #177820. In short, this bug means that no output is shown when an application is executed with a 64-bit JVM. There is luckily a work-around – setting up the IDE to use a 32-bit JVM even if you are running a 64-bit operating system.

The great news is that this issue has been fixed in the NetBeans 7.2 development builds (since 17 March 2012) for Ant-based projects! A big thanks to Jiri Rechtacek for this fix! :D

Edit: In my excitement about this fix I forgot to mention that this is specifically for NetBeans Platform applications. :-)

Originally all NetBeans Platform applications were built using the Ant-based build harness. And of course this option is still available in NetBeans 7.1. However, the IDE also has tool support for creating platform applications built with Maven, which was added in more recent versions.

I have been working with the NetBeans Platform since 5.5 days, and I have learned a good deal about the Ant build harness over the years. Last week I started a new job and now I am wrapping my mind around building a platform application using Maven. This is the first of an (as yet) unknown number of articles documenting the lessons that I am learning in this process about the differences between the two approaches. It is my hope that the information will make the mind shift from Ant to Maven easier for other developers. :)

One of the first questions that came to mind after I created my first Maven-based platform application, is “where did the Package As… menu go?” The context menu of an Ant-based suite used to contain a lot of separate packaging actions back in the day. More recently, all these actions (including the one that builds a zip file) were moved to the Package As… menu. But for my Maven project, no such menu was anywhere to be found!

After a brief moment of frustration, I decided to have a look at the folder structure of the project once it was built. And there I found a zip distro that looks identical to the one I would have expected from an Ant-based project. As it turns out, this always gets built when you build the application, and is stored in the application/target folder.

Another useful thing in the same location is the userdir folder – this is the equivalent of the build/testuserdir folder for an Ant-based application.

Read the Maven Best Practices wiki page for some more interesting information.

© 2012 NetBeans Ruminations Suffusion theme by Sayontan Sinha