Apr 242012
 

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:

[text]C:NetBeansharnesssuite.xml:502: The following error occurred while
executing this line:
C:NetBeansharnessrun.xml:198: The application is already running within
the test user directory.
You must shut it down before trying to run it again.[/text]

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

[text]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:ProjectsTeststest2applicationtargettest2bintest2.exe
(The process cannot access the file because it is being used by another
process) -> [Help 1][/text]

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

Apr 172012
 

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:

[text]mvn nbm:build-installers[/text]

Have a look at this AgroSense page for related information.

Apr 102012
 

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;
}

Apr 052012
 

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.

Edit: For more information about this, read Geertjan’s blog post about this topic.