How to create a sample apache wicket project in eclipse with maven?

In this tutorial, let us create a wicket sample application (wicketsample) in easy steps using wicket quick start with the help of maven.
The requirements to start a wicket project

1. Appache Wicket 6.16
2. Java : Java 1.6 or above
3. Maven
3. Eclipse with Apache Tomcat server

Let us create a sample wicket project with the following details

Step 1 : Create a sample web application

The quickest way to create a sample web application with proper web structure is to use maven

Run the following command in the command prompt in a folder where you want to create the workspace (In this example : f:\Eclipse\WorkSpace)

To run the above command, please ensure that maven is installed in your local machine. If not, please go through my eariler tutorial, how to install maven in windows 8?. Also i assume that maven repositry is created.

When you run the above command, it creates a sample web application (WicketSample) with in the current folder (F:\Eclipse\WorkSpace\WicketSample) with maven pom.xml that contains the configuration to build the project.

Step 2:  Add Wicket Dependencies for the project using maven i.e add necessary lines in the pom.xml to load necessary jars from mavan repository

pom.xml

Note : Wicket rquires SLF4J logging implementation which is to be added to your classpath

The complete pom.xml file for the sample wicket project is given below. You can simply replace it with the default one in the project. (i.e. in the folder F:\Eclipse\WorkSpace\WicketSample )

pom.xml

 

Step 3:  Replace the web.xml file located in the folder (F:\Eclipse\WorkSpace\WicketSample\src\main\webapp\WEB-INF) with the below web.xml file. Configure web.xml for the filter class of wicket application as given below.

web.xml

 

Step 4: Delete the index.jsp file from the webapp folder (F:\Eclipse\WorkSpace\WicketSample\src\main\webapp)

In wicket java files and html files are put in the source folder under src\main\java

Step 5: Go to the project folder under workspace (F:\Eclipse\WorkSpace\WicketSample) and run the below command to build the project

mvn eclipse:eclipse -Dwtpversion=2.0

Step 6: Open the Eclipse and import the workspace using File->Import->Existing projects into work space.import

Select the folder WicketSample and finish.

Step 7 : Create Sample Java class files and html using using wicket which are given below.
WicketTest.java

WicketTestApplication.java

WicketTest.html

Just put all the above files under src\main\java\com\javaonline

Directory Structure of the WicketSample project for your reference.

structure

Finally include the src folder (src\main\java\) in the class path. Don’t include resource folder in the class path.

Java Build path for the project looks like

WicketSample Build Path

Now Run the project and  get the below output. wicket sample output

 

Note : If you are using local maven repository, run the below command to let eclipse know the path to the maven repository.

 

Reference : Apache Wicket Quickstart

You may also like

Leave a Reply

Be the First to Comment!