Using the Quickstart Archetype
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").
What we'll do is create an empty shell application using Maven, then import the application into Eclipse to do the rest of the work.
For the tutorial, we're using a fresh install of Eclipse and an empty workspace at /Users/Howard/Documents/workspace
. You may need to adjust a few things for other operating systems or local paths.
From our workspace directory, we'll use Maven to create a skeleton Tapestry project.
Before proceeding, we have to decide on four things: A Maven group id and artifact id for our project, a version, and a base package name.
Maven uses the group id and artifact id to provide a unique identity for the application, and Tapestry needs to have a base package name so it knows where to look for pages and components.
For this example, we'll use the group id com.example, artifact id tutorial1, version 1.0-SNAPSHOT and we'll use com.example.tutorial as the base package.
Our final command line is:
mvn archetype:generate -DarchetypeCatalog=http:
It will then prompt you to pick the archetype - choose the latest Tapestry 5.X Quickstart Project, enter the group id, artifact id, version and package when prompted.
| The first time you use Maven, you'll see quite a bit more output, mostly about downloading all sorts of JARs and other files. 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 executing the command, you'll see a new directory, tutorial1.
| Maven Behind a Firewall If you are behind a firewall, before running any "mvn" commands, you will need to configure your proxy settings in 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:/Documents and Settings/joeuser/.m2/repository</localRepository>
</settings>
Of course, adjust the localRepository element to match the correct path for your computer. |
Running the New Application using Jetty
One of the first things you can do is use Maven to run Jetty directly.
Change into the newly created directory, and execute the command:
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), you'll see the following in your console:
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 hanlding. You can see that it has three different pages that share a common layout
.
| You should hit Control-C in the Terminal window to close down Jetty before continuing with the tutorial. |