NetBeans IDE

NetBeans Search & Replace with RegExp

NetBeans has a pretty powerful (and useful) search and replace feature that comes in handy when you want to manipulate a lot of text within one or many files. It’s power is magnified even more with superb regular expression support both for searching and replacing.

Recently I needed to create some xml tags using the text given below.

The input…


The output…(note that the text in bold above needs to be extracted as highlighted in the xml below)


This can be done easily by selecting “Edit/Replace” in NetBeans top menu and then providing the following regular expressions for the “Find What” and “Replace With” fields as shown below.


Find: ^keyword-(.*)\.html
Replace: <tocitem text=”$1″ target=”$1″>

Note how the relevant segment (highlighted in the xml sample) is extracted using parenthesis ( ) in the search expression which is then referenced using $1 in the replace expression. This can be done even when you want to capture multiple segments. In such situations the replace expression can use $2, $3,… etc.

Another excellent example of this functionality has been blogged here.

NetBeans IDE, Refactoring

NetBeans Refactoring Support

NetBeans has some great support for refactoring Java code.Recently I stumbled upon a nice feature when I wanted to do an extract method refactoring.

This is done easily by selecting the code segment you need to extract into a method and then right click and select Refactor/Introduce Method… menu option.

But then I was pleasantly surprised when NetBeans suggested to me that there are more occurances of the code I’m extracting into the method.

This came in handy as all the duplicate code (similar to the code I selected) was extracted into a single method in a flash!

ANT, Functional Test, NetBeans IDE, NetBeans RCP, Testing

Selectively running functional tests in NetBeans

Sometimes you may require to run only certain selected functional tests instead of running all tests in your NetBeans project. This is straightforward if you are doing it directly using the IDEs menu options in NetBeans since you can select the specific test file and run it.

But sometimes (e.g. Jenkins/Hudson CI) you may need to run selected functional tests from the command line. In such cases the first thing to note is that you must use the ‘test-single’ ANT target instead of the usual ‘test’ target to run your tests. You also have to provide two important parameters for it to work. They are ‘test.type’ and ‘test.includes’. The ‘test-type’ parameter should tell ANT to run ‘qa-functional’ tests and the ‘test-includes’ parameter should provide the actual functional test file name to be run. The ‘test-includes’ parameter can take wild cards therefore you can actually run multiple tests using the ‘test-single’ ANT target 🙂

Here’s an example, where I wanted to run all tests in org/acme/ide/projectbuild package which ends with ‘

D:\work\MyNBPlatformApp>ant -Dtest.type=qa-functional -Dtest.includes=org
/acme/ide/projectbuild/* test-single