Design Patterns, Java, Maven, Uncategorized

Missing ServiceProviders after Shading

Shading is a technique used in Maven to create a single”Uber” jar by merging the contents of  your app jar and all of it’s dependent jars. This makes it easier when distributing your application since there is only one big jar to deal with.

The Java Service Provider pattern is a cool way of building loosely coupled extensible applications.

When building a jar containing such implementations a text file per interface should be created listing all of it’s implementations and placed in META-INF/services. This is used by the JVM when the application needs to load (using ServiceLoader class) implementations of a particular interface without explicitly knowing about them.

The problem is when shading multiple jars containing service providers Maven does not merge the contents of META-INF/services by default.

The solution is to use the transformer ServicesResourceTransformer to tell the Shading plugin to merge the contents of META-INF/services in every jar it shades.

This can be specified in the pom.xml as shown below.

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
Development Tools, Java Enterprise Edition (JEE), JAX-WS

Wizdler a lightweight alternative to soapUI

Just came across an awesome Chrome extension to test SOAP Web Services (appropriately) called Wizdler. It’s really lightweight and comes in handy when you want to do a quick test of your web services specially during development. The simplicity of the UI really caught my attention, very intuitive and easy to use.

Once you enter your wsdl path in the address bar, Wizdler parses the wsdl contents (tounge twister alert!) and shows all available operations when you click the little icon at the end.


Clicking on an operation takes you to the request page where you fill in your request parameters for the web service (if any) and then simply click GO!


Of course it lacks many fancy features that soapUI offers, but you probably don’t need them all the time. The reason I looked for a Chrome extension was because I couldn’t seems to install soapUI on my Win7 box for some mysterious reason (problem with the 64-bit installer, me thinks).

‘Wizdler’ is no doubt a nifty little tool to test your SOAP web services on the fly with (almost?) “zero installations”!

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.

ANT, Java

Debugging ANT tasks when executing from the command line

Sometimes you may need to debug your custom Java ANT task (or even occasionally debug ANT source itself) when running from the command line. This can be achieved by setting ANT_OPTS as given below before running the “ant” command.

set ANT_OPTS=-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y


It might be a good idea to specify “suspend=y” as shown above since this will make the Java Virtual Machine (JVM) in which ANT executes to wait until you attach your debugger (from NetBeans of any IDE) along with the sources containing breakpoints.

This method can be used to debug ANT tasks running on a remote (build) server too without having to install an IDE and mounting source code in that particular server. This is made possible because the JVM opens a port for remote debugging which comes in handy not only for debugging ANT tasks but basically any java program that executes remotely.

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
ANT, Functional Test, Jenkins, JUnit, NetBeans RCP

NetBeans GUI tests on Jenkins + Windows

Running NetBeans application tests on Jenkins CI is quite easy. You just need to call the ‘test’ target in your NetBeans application’s build script (e.g. ANT build.xml) and Jenkins will do the rest. I initially setup Jenkins as a windows service to run my tests. This works fine for unit tests since they do not require a display to execute.

But recently I faced some issues when I wanted to run some functional (GUI) tests of a NetBeans platform app using a Jenkins job running on Windows. Since the Jenkins process could not access the windows display all the GUI tests were failing. On a linux box this issue is addressed by using X display such Xvnc (available as a Jenkins plugin), but of course I cannot use X display on windows!

After googling around I came across a possible solution which was to enable the option “Allow service to interact with desktop” for my Jenkins service. But as promising as it seemed it did not work, my GUI tests continued to fail 😦

Then I decided to stop and disable the Jenkins windows service and just ran it from the windows command prompt using the refreshingly simple command “java -jar jenkins.war”. Voila!!! It worked all my GUI tests were running without any problem and I can even see the GUIs opening and closing automagically on my windows desktop.

This solution was confirmed when I later stumbled upon the wiki here, which shows how to run GUI tests on ‘Hudson’ (Jenkins’ original name before Oracle knocked its head on a rock!) using a Tomcat container running on Windows. Although I didn’t use a servlet container such as Tomcat the solution applies to my situation as well.

So there you are, if you want to run GUI tests on Jenkins CI running on Windows do not configure it as a windows service instead run it from the command prompt or set it up as a scheduled task to run on windows logon using the command “java -jar jenkins.war”.