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 1 . 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://tapestry.apache.org
It will then prompt you to pick the archetype - choose Tapestry 5.2.4 Quickstart Project, enter the group id, artifact id, version and package when prompted.
~/Documents/workspace $ mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] [archetype:generate {execution: default-cli}] [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: http://tapestry.apache.org -> quickstart (Tapestry 5.2.4 Quickstart Project) 2: http://tapestry.apache.org -> tapestry-archetype (Tapestry 4.1.6 Archetype) Choose a number: : 1 Choose version: 1: 5.1.0.5 2: 5.0.19 3: 5.2.4 Choose a number: 3: 3 Define value for property 'groupId': : com.example Define value for property 'artifactId': : tutorial1 Define value for property 'version': 1.0-SNAPSHOT: Define value for property 'package': com.example: com.example.tutorial Confirm properties configuration: groupId: com.example artifactId: tutorial1 version: 1.0-SNAPSHOT package: com.example.tutorial Y: [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1 minute 41 seconds [INFO] Finished at: Wed Nov 17 17:00:16 PST 2010 [INFO] Final Memory: 16M/81M [INFO] ------------------------------------------------------------------------ ~/Documents/workspace $
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:
mvn jetty: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), you'll see the following in your console:
URLRewriter: DEFINED UpdateListenerHub: REAL ValidateBindingFactory: DEFINED ValidationConstraintGenerator: DEFINED ValidationMessagesSource: DEFINED ValidatorMacro: DEFINED ValueEncoderSource: DEFINED 85.00% unrealized services (153/180) 2010-11-17 17:06:30.630::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. You can see that it has three different pages that share a common layout 2 .
You should hit Control-C in the Terminal window to close down Jetty before continuing with the tutorial.
- Yes, Howard is on a Mac. Get one. ↩
- 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. ↩