Friday, June 13, 2008

Wicket in Action Quickstart

Wicket in Action is a cool book but, if you download the code associated with the book, you'll find the build doesn't work!   Spend less than five minutes correcting the build as I show here and you will have some cool Wicket functionality at your fingertips.

First, ensure you have Subversion, Maven and Java 1.5 or better installed correctly.

Next, get the code.   Open a Command Prompt window, change to the folder where you keep your source then start the download with this Subversion command:
C:\src\wicket\>svn checkout http://wicketinaction.googlecode.com/svn/trunk/ wicketinaction-read-only

When the download completes, the rights to the folder need to be changed.   Right-click on the wicketinaction-read-only folder and select properties.   On the General tab, deselect the Read-only property and then click Apply and Close.

Before we go further, determine if the problems I encountered in the build still exist in the project.   In the command window, change to the project folder and attempt to build and run the application:

C:\src\wicket\>cd wick*/book*
C:\src\java\wicket\wicketinaction-read-only\book-wicket-in-action>mvn clean package jetty:run-war -Djetty.port=9991

If the URL http://localhost:9991/wicket-in-action/home doesn't render the cover of the Wicket In Action book in your browser, please continue and complete the few simple changes to correct the problems in the build.

Problems in the Maven project file (pom.xml) the source folder structure need to be corrected so project will build and run.  Correct the directory structure by creating a main folder under the src folder and then moving the java, webapp and conf folder to fall under main as follows:
src/main/java
src/main/webapp
src/main/conf

The test code should be similarly configured in src/test/java.   Create a java folder under test and move the wicket folder to the test folder.

Now, fix the problems in the pom.xml file.   Edit the file and find <packaging>jar</packaging>. Change it to <packaging>war</packaging>.

Next, remove the entire <build> <resources> and replace with this:
<build>
  <resources>
    <resource>
      <filtering>false</filtering>
      <directory>src/main/conf</directory>
    </resource>
    <resource>
    <filtering>false</filtering>
    <directory>src/main/java</directory>
    <includes>
      <include>**</include>
    </includes>
    <excludes>
      <exclude>**/*.java</exclude>
    </excludes>
    </resource>
  </resources>
  <testResources>
    <testResource>
      <filtering>false</filtering>
      <directory>src/test/java</directory>
      <includes>
        <include>**</include>
      </includes>
      <excludes>
        <exclude>**/*.java</exclude>
      </excludes>
    </testResource>
  </testResources>


Now that we are done with the corrections to the build, we can run it ->

C:\src\java\wicket\wicketinaction-read-only\book-wicket-in-action>mvn clean package jetty:run-war -Djetty.port=9991

Open your browser to http://localhost:9991/wicket-in-action/home

Whoa - cool.

I've never had to correct a Maven build before.   This project appears to have been created manually and a Maven build then created around it.   In this case, the extra work was well worth the effort because the working application does an excellent job of demonstrating how Wicket works.   Dig into the code and see for yourself.