Pages

Tuesday, November 1, 2011

How to Easily Setup Apache Wicket with Maven

In this tutorial we will setup a “basic” Apache Wicket Project using Maven. In this setup it is assumed that you already have a Java Development Kit(JDK) installed.

What we need?

  1. Maven 3.03 which is the latest stable release at the time of writing.
  2. An IDE such as Eclipse or Netbeans.

What is Maven?

To know more about Maven please read the links below.

Installing Maven

Follow the Installation Instructions in Maven Website.

Building the Project

The most easy way to get started with Apache Wicket is to create a Wicket Quickstart Project with Maven. Apache wicket has provided a tool to generate the command line. In this example I will create a package/GroupId named “blogger.codeknowhow” which is where my HTML and Java files are located and a project name “hellowicket”. It is important to note that the project name or ArtifactId should be a single word.
mvn archetype:generate -DarchetypeGroupId=org.apache.wicket 
-DarchetypeArtifactId=wicket-archetype-quickstart 
-DarchetypeVersion=1.5.2 
-DgroupId=blogger.codeknowhow 
-DartifactId=hellowicket
-DarchetypeRepository=https://repository.apache.org/
-DinteractiveMode=false

Open command line or terminal and change directory to the directory where you want your project to be located.
cd path/to/myprojects

Copy and paste the generated code into the command line or terminal. If you have installed Maven correctly Maven will automatically download and setup the project.

Test your project change directory to your project directory in my case.
cd hellowicket

Inside the project directory start the jetty server.
mvn jetty:run

Maven will first compile our project and download all the dependencies that our Quickstart Project have setup. After that Maven will automatically start our jetty server. Now point your browser to http://localhost:8080 you should see

locahost

Open the Project to IDE

Eclipse

Eclipse needs to know the path to the local Maven repository. 
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
To generate the Eclipse project files from your POM
mvn eclipse:eclipse

In Eclipse choose FILE->IMPORT->EXISTING PROJECT and navigate to the folder where your project exist, then import.

Netbeans

Netbeans by default has Maven project support so just OPEN PROJECT(CTRL+SHIFT+O), then navigate to your project folder.
Now you can start developing your own wicket application!

2 comments:

  1. I'm just now learning about Wicket. I don't know Maven, and I found the quickstart a turnoff. I would like to set up Wicket from scratch, say using Jetty, but I can find how to do this nowhere. I'd like to try the Wicket examples, but I'm stuck. Drat!

    ReplyDelete
  2. The setup above should help you get started. Assuming you have done the setup above and want to try the "Hello World" example:
    1. Remove all existing files under "Source Packages" and under your created package add the HTML and Java files from the example.
    2. Remove existing files under "Other Test Sources".
    3. Replace/Edit the web.xml file under "Web Pages/WEB-INF/web.xml" with the sample web.xml.
    Note on this line under web.xml:
    org.apache.wicket.examples.helloworld.HelloWorldApplication

    replace it with:
    yourPackageName.HelloWorldApplication

    to make it work.

    4. Run/Restart the jetty server inside your project root directory using.
    mvn jetty:run

    5. Point your browser to http://localhost:8080

    This is supposed to be a tutorial series. I am busy ATM this is the fast that I'll be able to answer for now.

    ReplyDelete