Skip to main content

TOTD# 86: Getting Started with Apache Wicket on GlassFish

Posted by arungupta on July 30, 2009 at 6:01 AM PDT


cellspacing="5">
style="width: 339px; height: 75px;" alt=""
src="http://blogs.sun.com/arungupta/resource/images/wicket-logo.png">
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. href="http://wicket.apache.org/introduction.html">Why Wicket
digs more into the motivation behind this framework.



This Tip style="font-weight: bold;">Of style="font-weight: bold;">The style="font-weight: bold;">Day (TOTD) shows how
to create a simple Wicket application and get it
running on GlassFish:

  1. Create a Wicket project as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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]
    ------------------------------------------------------------------------
  2. Run it using the pre-configured Jetty plugin as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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:



    alt=""
    src="http://blogs.sun.com/arungupta/resource/images/wicket-helloworld-output.png">



    A later blog will show how to run this application using href="http://embedded-glassfish.dev.java.net/">Embedded
    GlassFish. But for now lets package the application as a WAR
    file and deploy it on GlassFish.

  3. Download href="https://glassfish.dev.java.net/downloads/v3-preview.html">GlassFish
    v3 Preview and unzip.
  4. Create a WAR file as:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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:


    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">
    ~/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:



    alt=""
    src="http://blogs.sun.com/arungupta/resource/images/wicket-helloworld-output-gfv3-preview.png">

Cool, that was pretty straight forward!



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 href="http://www.wicketframework.org/wicket-extensions/index.html">wicket-extensions
    for a list of gadgets/widgets that extend the core capability of the
    framework.

A few related blog posts planned:

  • Run Wicket application using Embedded GlassFish
  • Use href="http://blogs.sun.com/swchan/entry/servlet_3_0_web_fragment">Servlet
    3.0 web-fragments.xml and leverage GlassFish v3 Pluggability
    to run Wicket applications
  • A Wicket version of href="http://blogs.sun.com/arungupta/entry/track_your_running_miles_using">Track
    your running miles application
  • Deploying href="http://www.netbeans.org/kb/60/web/quickstart-webapps-wicket.html">Wicket
    applications from NetBeans to GlassFish

In the meanwhile, href="http://forums.java.net/jive/forum.jspa?forumID=56&start=0">let
us know if you are deploying your Wicket applications on
GlassFish.



Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available href="http://blogs.sun.com/arungupta/tags/totd">here.




Technorati: totd
wicket
glassfish
netbeans

Related Topics >>

Comments

Stay tuned, something coming on those lines next week.

Could you do a piece on using JavaEE with Wicket? That would be something really interesting! Thanks!