Ruby Programmer/Developer

George Armhold's Blog

Data-driven webapps built with Ruby, Java & Wicket

How to Get JNDI Working With Wicket 1.5 and Jetty 7.5

The Wicket 1.5 archetype sets up a project to use Jetty 7.5. Quite a lot has changed in Jetty since version 6, and this broke my JNDI config. Here’s how I put things right again.

First of all, the imports have all been moved in 7.x. ┬áHere’s where they landed:

import org.eclipse.jetty.webapp.WebInfConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebXmlConfiguration;

Next, you’ll need a jetty-env.xml.

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "">

<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
    <New class="">
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
            <Set name="Url">jdbc:mysql://localhost/mydatabase?characterEncoding=utf8</Set>
            <Set name="User">username</Set>
            <Set name="Password">password</Set>

Normally this goes into src/main/webapp/WEB-INF, but you probably don’t want to deploy that with your app in your production war file. So instead I put mine in src/test/jetty/jetty-env.xml. You’ll need to modify your to tell Jetty to find the relocated config file.

EnvConfiguration envConfiguration = new EnvConfiguration();
URL url = new File("src/test/jetty/jetty-env.xml").toURI().toURL();
bb.setConfigurations(new Configuration[]{
    new WebInfConfiguration(),
    new WebXmlConfiguration()

I found that I also had to set a couple of environment properties:


With this, I can finally access my JNDI datasource happily from Wicket/Jetty.

Update: I’ve created a gist with the full source code.

Automatically Generate Maven Dependency Coordinates for Random Jar Files

Have you just inherited an Ant project that you’re trying to convert to Maven? Maybe it came with a “lib” directory full or random jar files. And worse, some thoughtless developer neglected to include version strings in the filenames?

Fear not! The Sonatype checksum search┬áREST service can give you the Maven coordinates based on the jar’s SHA1 hash.

Still too much work? Not to worry, I just wrote a quick program to make it even easier for you. Provenance will take a directory full of jar files and write out the XML dependency information for every jar it finds. You can then copy/paste this right into the <dependencies> section of your pom.xml.


Adding Git SHAs to Wicket Pages Automatically

If you have a non-trivial project, it’s handy to be able to tell what code was used to build a particular release once it’s been deployed. Especially if you’ve recently discovered the joys of branching and merging with Git.

Here’s a handy way to add a Git SHA to all your app’s pages via Wicket and Maven.


First, we’ll use the exec-maven-plugin to create a file for us. Add this to the section in your pom.xml:

            <argument>--pretty=format:gitsha=%H %ci</argument>

This will create a file containing the Git SHA, along with the commit timestamp whenever your code is compiled. You can learn how to further customize this here.

Wicket Application Subclass

Now we’ll need to read in the file when our application starts up.

public class Application extends WebApplication
    private String gitSHA;

    public AppgravityApplication()
        java.util.Properties props = new java.util.Properties();
            gitSHA = props.getProperty("gitsha");
  "gitsha: " + gitSHA);
        catch (IOException e)
            gitSHA = "unknown";

    public String getGitSHA()
        return gitSHA;

Wicket WebPage Subclass

Now we’ll create a WebPage subclass that renders the Git SHA into a tag when the page is rendered.

public abstract class MyPage extends WebPage
    protected void onBeforeRender()
        Label metaGitSHA = new Label("metaGitSHA", "");
        metaGitSHA.add(new AttributeModifier("content", Model.of(((Application) getApplication()).getGitSHA())));

You’ll want to extend MyPage for each of your pages. You’ll need to add the placeholder meta tag to each of your HTML pages like this:

    <meta wicket:id="metaGitSHA" id="metaGitSHA" name="metaGitSHA" content=""/>

And you’re done!