TOTD# 86: Getting Started with Apache Wicket on GlassFish
Posted by arungupta on July 30, 2009 at 9:01 AM EDT
![]() |
Apache Wicket is an application framework to build web applications using HTML for markup and POJOs to capture the business logic and all other processing. Why Wicket digs more into the motivation behind this framework. |
This Tip Of The Day (TOTD) shows how to create a simple Wicket application and get it running on GlassFish:
- Create a Wicket project as:
~/samples/wicket >mvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=1.3.6 -DgroupId=org.glassfish.samples -DartifactId=helloworld
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:create]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] Defaulting package to group ID: org.glassfish.samples
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: wicket-archetype-quickstart:1.3.6
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.glassfish.samples
[INFO] Parameter: packageName, Value: org.glassfish.samples
[INFO] Parameter: package, Value: org.glassfish.samples
[INFO] Parameter: artifactId, Value: helloworld
[INFO] Parameter: basedir, Value: /Users/arungupta/samples/wicket
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] OldArchetype created in dir: /Users/arungupta/samples/wicket/helloworld
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Tue Jul 28 15:30:21 PDT 2009
[INFO] Final Memory: 12M/80M
[INFO] ------------------------------------------------------------------------ - Run it using the pre-configured Jetty plugin as:
~/samples/wicket/helloworld >mvn jetty:run
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO] ------------------------------------------------------------------------
[INFO] Building quickstart
[INFO] task-segment: [jetty:run]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 2 source files to /Users/arungupta/samples/wicket/helloworld/target/test-classes
[INFO] [jetty:run]
[INFO] Configuring Jetty for project: quickstart
[INFO] Webapp source directory = /Users/arungupta/samples/wicket/helloworld/src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = /Users/arungupta/samples/wicket/helloworld/target/classes
2009-07-28 15:31:35.820::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /helloworld
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
. . .
INFO - WebApplication - [WicketApplication] Started Wicket version 1.3.6 in development mode
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode. ***
*** ^^^^^^^^^^^ ***
*** Do NOT deploy to your live server(s) without changing this. ***
*** See Application#getConfigurationType() for more information. ***
********************************************************************
2009-07-28 15:31:37.333::INFO: Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server
And the default web page is available at "http://localhost:8080/helloworld" and looks like:

A later blog will show how to run this application using Embedded GlassFish. But for now lets package the application as a WAR file and deploy it on GlassFish. - Download GlassFish v3 Preview and unzip.
- Create a WAR file as:
~/samples/wicket/helloworld >mvn package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building quickstart
[INFO] task-segment: [package]
. . .
[INFO] Processing war project
[INFO] Webapp assembled in[494 msecs]
[INFO] Building war: /Users/arungupta/samples/wicket/helloworld/target/helloworld-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Tue Jul 28 15:35:59 PDT 2009
[INFO] Final Memory: 14M/80M
[INFO] ------------------------------------------------------------------------
and deploy as:
~/samples/wicket/helloworld >~/tools/glassfish/v3/preview/glassfishv3/bin/asadmin deploy target/helloworld-1.0-SNAPSHOT.war
Command deploy executed successfully.
The app is now accessible at "http://localhost:8080/helloworld-1.0-SNAPSHOT" and looks like:

Now that's a very vanilla application but at least shows that Wicket applications can be deployed on GlassFish out-of-the-box. A slightly more complex application will be shared on this blog in future.
Here are some more useful links for Wicket:
- Wicket Quickstart shows how to create a Wicket application and get started easily.
- Wicket Examples provide a flavor of how the code is structured.
- Wicket in Action is a great book that explains the concepts very well.
- May want to look at wicket-extensions for a list of gadgets/widgets that extend the core capability of the framework.
- Run Wicket application using Embedded GlassFish
- Use Servlet 3.0 web-fragments.xml and leverage GlassFish v3 Pluggability to run Wicket applications
- A Wicket version of Track your running miles application
- Deploying Wicket applications from NetBeans to GlassFish
Please leave suggestions on other TOTD that you'd like to see. A complete archive of all the tips is available here.
Technorati: totd wicket glassfish netbeans
Related Topics >>
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 1349 reads







Comments
by arungupta - 2009-07-30 18:39
Stay tuned, something coming on those lines next week.by alangarf - 2009-07-30 18:37
Could you do a piece on using JavaEE with Wicket? That would be something really interesting! Thanks!