Before we can get down to the fun, we have to create an empty application. Tapestry uses a feature of Maven to do this: archetypes (a too-clever way of saying "project templates").
For the tutorial, we're using a fresh install of Eclipse and an empty workspace at /users/joeuser/workspace
. You may need to adjust a few things for other operating systems or local paths.
Using the Quickstart Archetype
From Eclipse, we'll use a Maven archetype to create a skeleton Tapestry project.
Maven Behind a Firewall
If you are behind a firewall/proxy, before performing any Maven downloads, you may need to configure your proxy settings in your Maven settings.xml file (typically ~/.m2/settings.xml). Here is an example:
<settings> <proxies> <proxy> <active>true</active> <protocol>http</protocol> <host>myProxyServer.com</host> <port>8080</port> <username>joeuser</username> <password>myPassword</password> <nonProxyHosts></nonProxyHosts> </proxy> </proxies> <localRepository>C:/Users/joeuser/.m2/repository</localRepository> </settings>
Of course, adjust the localRepository
element to match the correct path for your computer.
Okay, let's get started creating our new project.
In Eclipse, go to File > New > Project... > Maven > Maven Project
Then click Next, Next (again), and then on the Select an Archetype page click the Configure button on the Catalog line. The Archetype preferences dialog should appear. Click the Add Remote Catalog... button:
As shown above, enter "http://tapestry.apache.org" in the Catalog File field, and "Apache Tapestry" in the Description field.
If you want to try an unreleased (alpha or beta) version of Tapestry, use https://repository.apache.org/content/repositories/staging archetype catalog file instead.
Click OK, then OK again.
On the Select an Archetype dialog, select the newly-added Apache Tapestry catalog, then select the "quickstart" artifact from the list and click Next.
Fill in the Group Id, Artifact Id, Version and Package as follows:
then click Finish.
The first time you use Maven, project creation may take several minutes as Maven downloads hundreds of JAR dependencies. These downloaded files are cached locally and will not need to be downloaded again, but you do have to be patient on first use.
After Maven finishes, you'll see a new directory, tutorial in your Package Explorer view in Eclipse.
Running the Application using Jetty
One of the first things you can do is use Maven to run Jetty directly.
Right-click on the tutorial project in your Package Explorer view and select Run As > Maven Build... >, enter a Goal of "jetty:run". This creates a "Run Configuration" named "tutorial1" that we'll use throughout this tutorial to start the app:
Click Run.
Again, the first time, there's a dizzying number of downloads, but before you know it, the Jetty servlet container is up and running.
Once Jetty is initialized (which only takes a few seconds after the first time), you'll see the following in your console:
ValidationConstraintGenerator: DEFINED ValidationDecoratorFactory: DEFINED ValidatorMacro: DEFINED ValueEncoderSource: DEFINED 86.77% unrealized services (164/189) Application 'app' (version 1.0-SNAPSHOT-DEV) startup time: 87 ms to build IoC Registry, 376 ms overall. ______ __ ____ /_ __/__ ____ ___ ___ / /_______ __ / __/ / / / _ `/ _ \/ -_|_-</ __/ __/ // / /__ \ /_/ \_,_/ .__/\__/___/\__/_/ \_, / /____/ /_/ /___/ 5.3.7 (development mode) 2011-11-22 11:46:45.636::INFO: Started SelectChannelConnector@0.0.0.0:8080 [INFO] Started Jetty Server
You can now open a web browser to http://localhost:8080/tutorial1/ to see the running application:
The date and time in the middle of the page proves that this is a live application.
This is a complete little application; it doesn't do much, but it demonstrate how to create a number of pages sharing a common layout, and demonstrates some simple navigation and link handling. You can see that it has three different pages that share a common layout. (Layout is a loose term meaning common look and feel and navigation across many or all of the pages of an application. Often an application will include a Layout component to provide that commonness.)