November 15, 2012

A Better Maven POM for Wicket Archetypes

If you are new or just wants to try Apache Wicket there is a good Wicket Maven Archetype for that. You can find instruction for that at http://wicket.apache.org/start/quickstart.html.

But the generated pom.xml leafs room for improvement. A better pom would be

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>se.msc.examples</groupId>
    <artifactId>example-wicket</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Example Wicket</name>
    <organization>
        <name>MSC</name>
        <url>www.msc.se</url>
    </organization>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.outputEncoding>UTF-8</project.build.outputEncoding>
        <wicket.version>6.2.0</wicket.version>
        <jetty.version>7.5.0.v20110901</jetty.version>
    </properties>
    <dependencies>
        <!-- WICKET DEPENDENCIES -->
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-core</artifactId>
            <version>${wicket.version}</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-extensions</artifactId>
            <version>${wicket.version}</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.wicket</groupId>
            <artifactId>wicket-datetime</artifactId>
            <version>${wicket.version}</version>
        </dependency>

        <!-- LOGGING DEPENDENCIES - LOG4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

        <!-- JUNIT DEPENDENCY FOR TESTING -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

        <!-- JETTY DEPENDENCIES FOR TESTING -->
        <dependency>
            <groupId>org.eclipse.jetty.aggregate</groupId>
            <artifactId>jetty-all-server</artifactId>
            <version>${jetty.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</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/resources</directory>
            </testResource>
            <testResource>
                <filtering>false</filtering>
                <directory>src/test/java</directory>
                <includes>
                    <include>**</include>
                </includes>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>1</scanIntervalSeconds>
                    <useTestClasspath>true</useTestClasspath>
                    <connectors>
                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                            <port>8080</port>
                            <maxIdleTime>3600000</maxIdleTime>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The differences I made are the following.

1. Downgrade the Jetty Maven Plugin to 7.5.0.v20110901

<jetty.version>7.5.0.v20110901</jetty.version>

The new jetty plugin are much slower than the old one and you want miss anything important.

2. Add Wicket Datetime Dependency

<dependency>
    <groupid>org.apache.wicket</groupId>
    <artifactid>wicket-datetime</artifactId>
    <version>${wicket.version}</version>
</dependency>

Wicket provides a good datetime picker and I recommend that you use this.

3. Configure Jetty Maven Plugin for Autodeploy

<scanintervalseconds>1</scanIntervalSeconds>

The jetty plugin can automatically be configure to pick up any changes made within Eclipse and automatically redeploy your application. This is a great way to develop and I recommend it.

<usetestclasspath>true</useTestClasspath>

You also might want to mock any possible server facade class, which is located in your test directory. To enable that add your web test classes to jetty classpath.

No comments: