Apache Wicket is a lightweight component-based web application framework for Java. This document explains how to write the first program in Apache Wicket and run it.
-
Prerequisite
For Apache Wicket to run, first you will need to install JDK – Java Development Kit. And for building the application you will need to install Maven. To run an application you need any web server or application server. Here we are using JBoss Application Server. The Apache Wicket version used is Wicket-6.15.0 and Eclipse version used is Eclipse Juno v4.2.
-
Now Run the application with JBoss Application Server. The Application will display a message
Hello World
on the screen. -
Apache Wicket Hello World Program
Once the JDK and Maven setup is done, create
apache-wicket
directory in C drive. Go to command prompt, change the directory toC:\apache-wicket
and run below code.mvn archetype:generate -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=6.15.0 -DgroupId=com.example -DartifactId=myproject -DarchetypeRepository=https://repository.apache.org/ -DinteractiveMode=false
The above line will create a project structure in the directory
C:\apache-wicket
. Once executed successfullyBUILD SUCCESS
message will be displayed on the console.Now open Eclipse IDE. Give the folder path
C:\apache-wicket
in eclipse workspace.Import the project created with Maven into eclipse workspace. Use eclipse menu
File -> Import..
to import the source code and available for editing.Browse the folder in root directory
C:\apache-wicket
. The project named myproject will be listed inProjects
, showingpom.xml
maven build file. Click the Finish button to complete the import.The project structure will be created in eclipse,
Project Explorer
.Now write code for first apache wicket program inside package
com.example
.HelloWorld.java
package com.example; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; public class HelloWorld extends WebPage { public HelloWorld() { add(new Label("message", "Hello World!")); } }
HelloWorld.html
Apache Wicket Hello World <span>Message goes here</span>
Now edit code for below files.
WicketApplication.java
package com.example; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.protocol.http.WebApplication; public class WicketApplication extends WebApplication { /** * @see org.apache.wicket.Application#getHomePage() */ @Override public Class&amp;lt;? extends WebPage&amp;gt; getHomePage() { return HelloWorld.class; } }
Web.xml
ApacheWicketExample wicket.myproject org.apache.wicket.protocol.http.WicketFilter applicationClassName com.example.WicketApplication wicket.myproject /*
Now Run the application with JBoss Application Server. The Application will display a message
Hello World
on the screen.
Find the Source Code on GitHub: Apache Wicket.