During an average day working on an Ant-based NetBeans Platform application, a developer would constantly use the project actions such as “Build”, “Clean” and “Test” in the NetBeans IDE. But when the application needs to be built on a build server, a way needs to be found to perform these actions from the command line. Since the projects are already Ant-based, and the actions in the IDE are linked to Ant build scripts, this is luckily straight forward. The only question is which target(s) to call.

For more information about the Ant-based build harness and how it is structured, have a look at this article. (Note that there are multiple parts, and part 2 is especially useful in this context.) But for now the only really important part to note is that all Ant-based NetBeans Platform Applications (suites) and modules have a build.xml file.

Before listing the Ant targets that are generally useful, I would like to explain how to find them yourself. The first and most difficult way is to find the action in the IDE source code. I have done this before, but it is in almost all cases complete overkill. :) The second option is to expand the Build Script under Important Files in the project, to see a complete list of all the targets that are available. While this is much easier, it is still not the most direct route.

The best option in almost all cases is to perform the action and then look at the title of the Output window. The name of the project appears there, followed by the target(s) in brackets.

Targets applicable to NetBeans module projects

  • netbeansBuild action in the IDE – compile the module, creating artifacts in the build folder of the module as well as the build folder of the suite
  • cleanClean action in the IDE – removes the contents of the module’s build folder
  • nbmCreate NMB action in the IDE – creates an nmb file for the module in its build folder
  • test-unitTest action in the IDE – executes the unit tests in the module and creates artifacts in the build/test folder of the module

Note: For standalone modules, the same targets apply. The difference is that for the netbeans target, all the artifacts are placed in the module’s build folder.

Targets applicable to NetBeans Platform application suites

  • buildBuild All action in the IDE – builds all the modules contained in the suite
  • cleanClean All action in the IDE – cleans all the modules in the suite and removes the build and dist folders of the suite
  • build-zipPackage as > ZIP Distribution action in the IDE – builds all the modules in the suite and then creates a .zip file in the dist folder of the suite
  • nbmsPackage as > NBMs action in the IDE – builds all the modules in the suite and then creates a .nbm for each of the modules in the suite’s build/updates folder
  • testTest All action in the IDE – executes the unit tests in each of the modules contained in the suite and creates artifacts in the build/test folder of each module

A recent question on the NetBeans Platform Users forum made me think again about the layer file and its current place in the platform. And so I decided to write this post. Note that this post is about the NetBeans Platform, and specifically version 7.1.

The layer file used to be the place where almost all extensions to the NetBeans Platform got registered. So what do I mean by extensions? When you are developing a NetBeans module, some of the typical things you might want to do is create new windows and menu items and toolbar buttons. These all plug into and extend the platform’s window system. The wizards provided by the IDE to simplify the creation of these extensions, created the layer file entries as well as the classes containing the actual functionality. At runtime the platform reads all the information in the layer file and uses those registrations to load the right classes and use them in the appropriate ways.

And then came the annotations. This is another way of representing the same information by applying annotations directly on the classes instead of keeping the registrations in a separate file. As far back as version 6.7 some annotations were introduced. (See Geertjan’s blog post about the annotations implemented back then.) Slowly but surely the layer file entries in the platform were replaced by the much more maintainable annotations. And in version 7.1 the platform is now at the point where pretty much all the extensions are no longer directly based on layer file registrations.

On a side note. I say ‘directly based’ because there is still a layer file in the background. Many (but not all) of the annotations have a source level retention (for example TopComponent.Registration). These annotations are processed at compile time, and one of the possible outputs is a generated layer file. The generated file will appear in the module’s .jar file once it is built, in the META-INF folder and will be called generated-layer.xml.

With the advent of this moment, another small but noticeable change was made. The new module wizard no longer allows the user to choose to create a layer file. It was the logical thing to do, since in almost all cases the layer file would remain empty and having an empty layer file contributing to the file system is inefficient. And for the rare cases where you still need a layer file, there is now a new file wizard that allows you to create one. It can be found at File > New File… under the Module Development category.

The layer file is dead… long live the layer file!

One of the new features of the NetBeans IDE in version 7.1 is the Visual Debugger. The Visual Debugger allows you to easily find the source code for GUI components. Read the tutorial Using the Visual Debugger in NetBeans IDE for more information.

NetBeans 7.1 has been released! Read more about the new version in Geertjan’s news report.

Edit: Also read Geertjan’s blog post.

The NetBeans Platform allows you to define file types. Each file type has its own behaviour associated with it. The File Type Integration Tutorial provides a lot of information about how the file types can be created and customised.

With NetBeans Platform 7.1, it is now possible to register a file type with the @TemplateRegistration annotation instead of using the layer file. To manually convert an existing file type (read the tutorial to find out how to create one) to use the new annotation, follow these steps:

  1. Remove the contents of the layer file.
  2. Add a package-info.java file to the module, containing the following:
@org.netbeans.api.templates.TemplateRegistration(folder="Other",
    content="ABCTemplate.abc", displayName="Empty ABC file")
package org.myorg.abcfiletype;

Clean and build the module, and inspect the generated layer file to see the result. The generated layer file will be located at build/cluster/modules/AbcFileType.jar/META-INF/generated-layer.xml.

While searching for a NetBeans IDE related topic today, I discovered an absolute gem: a whole page full of useful NetBeans Tips! Have a look at http://wiki.gephi.org/index.php/NetBeans_Tips

I use the search features of the NetBeans IDE a lot. I have collected thousands of pieces of useless information in my life as it is, and I am not planning to add to that memorising every line of code I have ever written. :) So I let my PC do what computers do best – search through large volumes of data. This has become an integral part of how I work, but I realised this week that not everybody knows about all the cool things you can do!

The NetBeans IDE have a number of very useful searching features. The first, and probably most obvious, is searching through the currently selected source file. I created two new Windows in a platform application module through the wizard for illustration purposes. I opened one of the TopComponent classes in source view, and pressed Ctrl + F and typed in my search term. See the figure below.

Searching through a source file

Searching through a source file

Notice that a search bar appeared at the bottom of the editor window, where I entered my search string. And as I typed, matching words were highlighted throughout the currently selected source file. The highlighted words are also marked in the right margin – each of those lines in the margin represent a line where the search term was found. Pressing enter while the Find text box has focus, moves the selection to the next occurrence of the search term.

If you select something in the source file before you press Ctrl + F, that text will automatically be filled in on the search panel.

This is useful but not life changing. :) But searching, like almost everything in the IDE, is context sensitive. So by selecting a project in the projects view, and then pressing Ctrl + F again, you can access the Find in Projects feature.

Find in Projects

Find in Projects

Since I selected a particular project, that project is selected by default as the scope for the search. Pressing Ctrl + Shift + F instead from anywhere in the IDE, the Scope would by default be “Open Projects”.

Let us look at the search results for the criteria “TopComponent”, searching through my module containing the two Windows.

Search results

Search results

The list shows all the files where the search criteria were matched, and for each file the list of occurrences within the file. Navigating to the location is as simple as double clicking on the entry.

I guess I should have realised that starting a new blog on the 13th (even though it was not a Friday), might be a bad idea. :) Soon after the first post I experienced technical difficulties with the server. Today I finally got around to setting everything up again, so here is the first real post. :)

One of my favourite features of the NetBeans IDE is source formatting. With the press of a few buttons (Alt + Shift + F) (or Source | Format from the menu bar), you can convert a real mess…

package javaapplication1;public class JavaApplication1 {/*** @param args the command line arguments*/public static void main(String[] args) {System.out.println("Hallo World!");}}

into something a lot more readable…

package javaapplication1;

public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Hallo World!");
    }
}

The format is highly configurable, to suit the preferences of all developers. The settings can be accessed from Tools | Options, in the Editor category on the formatting tab.

Source formatting is not limited to Java source code though – it works equally well for XML. For example, from

<?xml version="1.0" encoding="UTF-8"?><root><tag1><tag2><tag3></tag3></tag2></tag1></root>

to

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <tag1>
        <tag2>
            <tag3></tag3>
        </tag2>
    </tag1>
</root>

Welcome to NetBeans Ruminations – my new blog about… the NetBeans IDE. :) I have been writing articles about interesting NetBeans platform topics for a while now. But I have realised again that there is a wealth of incredible features in the NetBeans IDE that deserve mention. Features that truly help developers to be more productive. And so, just before the release of NetBeans 7.0, I have started writing this blog.

© 2012 NetBeans Ruminations Suffusion theme by Sayontan Sinha