January 2, 2013

How to Debug and Run Apache Wicket Quickstart with Jetty Web Server

Introduction

The development environment for Apache Wicket is really good. In this blog I will show you how to run Apache Wicket web application with the maven jetty plugin, but also how to debug your web application.

How to run with Maven Jetty Plugin

First lets get started with creating a simple Apache Wicket web application with the wicket maven archetype. If you are not familiar with maven archetype, please read http://maven.apache.org/guides/introduction/introduction-to-archetypes.html. To get the latest version of Apache Wicket, please visit http://wicket.apache.org/start/quickstart.html. In this blog I will make some changes to this Apache Wicket Quickstart, which I will describe below and why I have made them.

First remove the extra repository from the archetype command. This extra repository is not necessary and In my opinion you should as far as possible stick with standard repository, as long as possible. The final archetype command I used looks the following:

After finished you can import the maven project into Eclipse or you preferred IDE. Now open the pom.xml. I made the following changes.

1. Add UTF-8 encoding to reporting.

2. Add wicket extra dependency.

3. Add the following configuration to the jetty-maven-plugin.

The scanIntervalSeconds configuration makes the jetty web server automatically restart whenever you make changes in you IDE. This makes coding easy and you can directly see you changes in your web browser.

The next configuration (useTestClasspath) adds you test code to the jetty web server classpath. This is convenient if you want to mock your server facade.

And with last configuration (webXml) you can switch the standard web.xml with a completely mocked web.xml, which may contain no security classpaths to you mocked classes.

To run the maven jetty plugin, simply open a terminal and write

How to Debug with Jetty Web Server

The last and maybe the most imported is the debug capability. The Apache Wicket archetype comes also with a jetty web server that is started from a java class /src/test/java/se/msc/examples/Start.java. And if you do not need the SSL support I recommend you to comment that code out. Now simple right click on Start class and select Debug As → Java Application. Add breakpoints and open that page in you web browser. Easy and elegant.

References:

No comments: