We’re going to walk through the process of configuring Apache Wicket to run in Tomcat rather than its default Jetty Server. There are several approaches to using Tomcat with a Wicket web application in Eclipse, including starting from scratch with handwritten Java, HTML and web.xml files and referencing the required JARs. Instead we’re going to use Eclipse and Wicket Quickstart to do the heavy lifting for us.
Here are the steps we’ll be performing to get our Wicket site up and running with Tomcat.
- Create a Dynamic Web Project in Eclipse
- Generate a Wicket Quickstart Project in Maven
- Transfer Wicket essentials of Quickstart to our Web Project
- Add Wicket JARs to our build
- Update our web.xml
- Fire up the Wicket project in Tomcat
Create a Dynamic Web Project in Eclipse
We begin by creating a Dynamic Web Project in Eclipse named jangleswicket. We create it like any other Dynamic Web Project. Once it’s created we’ll move on and come back to it in a bit.
Generate a Wicket Quickstart Project
I should mention before continuing that we already downloaded the Wicket JARs as well as its SLF4J Logging JAR dependencies to a directory outside of Eclipse. We also have Maven running on our machine. With those steps complete we can use Apache Wicket’s Quickstart Maven generation utility to construct the Maven script and create our Wicket Quickstart project.
We run the maven script to create the wicket project followed by adding the Eclipse goodness.
Transfer Wicket essentials of Quickstart to our Web Project
We added Wicket Quickstart to the Eclipse workbench so that we can copy its essentials to Jangleswicket. We only need a few items from Quickstart, the contents in /src/main and /src/main/webapp.
Two additional points here. First, we created a com.nixmash.jangleswicket package to store Wicket Java and HTML files. Also, we copied the Wicket /src/main/webapps into the Eclipse Dynamic Web Project’s standard /WebContent folder. We could maintain the Wicket Maven structure and use /src/main/webapps, but we’re going to use Ant and want our familiar /WebContent as the application root.
Here’s jangleswicket with the required contents of the wicket Quickstart project.
Add Wicket JARs to our build
Next we add the essential Wicket JARs to a /lib directory and add them to our build. We only really need log4j, slf4j-api, sfl-log4j and wicket-core here, but were adding additional wicket libraries just because.
Update our web.xml
The final step is to modify /WebContent/WEB-INF/web.xml so that Wicket finds the application Java files in the new package.
Fire up the Wicket project in Tomcat
We’ve added jangleswicket to our Tomcat Server list in Eclipse Server View so now we’re ready to fire it up.
Boom, Baby! The Wicket HomePage.html loaded and we know we’re wired correctly because the “version” label has populated with the current version of Wicket, generated from the Wicket Homepage.java source.