Pages

Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

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!