Thursday, December 1, 2011

How to trigger a build in Jenkins for each commit in Mercurial

Just add the following to the hgrc file in the project's hg directory:

[hooks]
commit.jenkins = java -jar <path to jenkins-cli.jar> -s http://<Jenkins URL>/ build -c <project name>
To get the jenkins-cli.jar file, follow the instructions in this post.

More information on Mercurial hooks can be found in Mercurial: The Definitive Guide.

How to trigger a Jenkins build from command-line

To trigger a Jenkins build from command-line is pretty simple. In *nix, you can use wget to trigger the build via a HTTP request. If you don't have that kind of tool available on your platform (e.g. Windows), the CLI-client is a useful option.

First you need to download the client jar file; you can get this from http://<your Jenkins server>/cli. Place the jar file in an accessible location.

To start the build, just issue the command:
java -jar jenkins-cli.jar -s http://<your Jenkins server>/ build <project name>

Sunday, September 4, 2011

GlassFish v3: Picky about where the libraries in an EAR are located

While trying to deploy an EAR-application on GlassFish v3, I got an error about missing class files. The mentioned class files where from external libraries packaged along with my EJB inside the ear-file. I found this strange since the same ear-file deployed just fine on GlassFish v2. Strange...

After a couple of hours with trial-and-error and my favorite troubleshooter (Google), I came across another guy who had similar problems. It turned out that GlassFish v3 is more picky about where libraries are located. The short answer: Just add a simple line in the pom.xml:
<library-directory>lib</library-directory>

killall in Windows

Recently I ran into a serious annoyance while using a Windows computer at work. Something triggered a cascade of processes that crashed and spawned other Dr Watson-threads. This bugged down my computer enough to be pain in the ass, and I didn't want to use the reset button on my computer, so I opened the Task Manager and looked for something that resembled killall from Unix. No such luck.

Once more Google provided me with a solution. How-to Geek had written an article about the taskkill utility in Windows:
taskkill /F /IM <processname.exe> /T

How to use a global ignore file in Mercurial

I got tired of manually adding common elements to the .hgignore-file, so after some quick research the option for a global ignore file presented itself as the solution to my problem.

Just a few lines in the Mercurial user file is needed:
[ui]
ignore = C:\<some path>\mercurial.ignore
Example content for the ignore-file:
target
 This information is also available in the user manual.

Friday, July 8, 2011

Web harvesting and GUI testing with WebDriver

For a spare time project I've been working on lately, I had to web harvest (also known as screen scraping) a couple of web pages to get the information I needed. A coworker recommended WebDriver, a part of Selenium testing framework.

In a nutshell, WebDriver is a library that controls your browser from code. This can be useful when doing GUI testing or when you want to simulate a web browser to fetch something from the web.

You can control different browsers (Firefox, Chrome, etc). In my experiment I used Firefox. WebDriver currently only support version 3 of Firefox, so I had to download it and point WebDriver to where it was located.

WebDriver worked very well for my project and even though I'm not a big fan of web harvesting the overall result was good enough.

How I pointed WebDriver to Firefox 3 and turned on autodownload for Excel spreadsheets:
        System.setProperty("webdriver.firefox.bin", "/opt/firefox-3.6/firefox/firefox");
        FirefoxProfile fp = new FirefoxProfile();
        fp.setPreference("browser.download.dir", "/tmp/firefox-webdriver");
        fp.setPreference("browser.download.folderList", 2);
        fp.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/mx-msdownload");

        WebDriver driver = new FirefoxDriver(fp);
The Maven dependency looks like this:
        <dependency>
            <groupId>org.seleniumhq.webdriver</groupId>
            <artifactId>webdriver-firefox</artifactId>
            <version>0.9.7376</version>
        </dependency>

Tuesday, July 5, 2011

My list of recomended reading for software developers

Here is a list of books and online resources that I would recommend to fellow developers.

General books
Java books