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.

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”.

ANT, Development Tools

ANT’s XmlProperty task

Recently I needed to extract all the EJBs declared in an ear’s application.xml from within an ANT build script. At first I thought this may need a custom ANT task in order to do it cleanly or else I may have to do some messy file/string processing using ‘existing’ (to my knowledge) ANT tasks.

But if ANT itself is based on XML I’m sure it should have some tasks for working with XML files. Googling resulted in a task I had never heard of before, XmlProperty.

This is a really powerful yet easy to use ANT task which parses an input XML file and places the contents in ANT properties that correspond to tag names defined in the XML file. Exactly what I wanted!!!!!

So here goes…my application.xml file looks something like this

<application version="5" 
             [...removed for brevity...]">
   <display-name>My Application</display-name>

What I need is to get a delimited list of ejb’s declared in the XML file above. ANT to the rescue! Note that the ANT property name application.module.ejb below corresponds to the tag names found in the application.xml above.

<target name="ejb-lister">
     <xmlproperty file="${}/META-INF/application.xml"/> 
     <echo>#### ${application.module.ejb} ####</echo>

Shown below is the output when I execute the “ejb-lister” target. As you can see I get a comma separated list of EJBs declared in the application.xml

#### customermanager-ejb.jar, suppliermanager-ejb.jar, ordermanager-ejb.jar, movierentals-ejb.jar####
BUILD SUCCESSFUL (total time: 0 seconds)

The tasks has quite a few parameters (refer ANT doc) especially the delimiter, which can be given if you need to use something other than comma which is the default.

Of course this task can be used to parse any well-formed XML file which in my case happens to be an EAR’s application.xml!