Creating The Skeleton Application

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/joeuser/workspace. You may need to adjust a few things for other operating systems or local paths.

Using the Quickstart Archetype

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:

Icon

If you want to try an unreleased (alpha or beta) version of Tapestry, use https://repository.apache.org/content/repositories/staging archetype catalog URL instead.

You will then be prompted to pick the archetype - choose the latest Tapestry 5.X Quickstart Project, enter the group id, artifact id, version and package when prompted.

$ mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom >>>
[INFO] 
[INFO] <<< maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom <<<
[INFO] 
[INFO] --- maven-archetype-plugin:2.1:generate (default-cli) @ standalone-pom ---
[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 -> org.apache.tapestry:quickstart (Tapestry 5 Quickstart Project)
2: http://tapestry.apache.org -> org.apache.tapestry:tapestry-archetype (Tapestry 4.1.6 Archetype)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Choose version: 
1: 5.0.19
2: 5.1.0.5
3: 5.2.6
4: 5.3.7
Choose a number: 4: 4
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] Using following parameters for creating project from Archetype: quickstart:5.3.7
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: artifactId, Value: tutorial1
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.example.tutorial
[INFO] Parameter: packageInPathFormat, Value: com/example/tutorial
[INFO] Parameter: package, Value: com.example.tutorial
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: com.example
[INFO] Parameter: artifactId, Value: tutorial1
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/test/java
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/main/webapp
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/main/resources/com/example/tutorial
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/test/resources
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/test/conf
[WARNING] Don't override file /Users/joeuser/workspace/tutorial1/src/site
[INFO] project created from Archetype in dir: /Users/joeuser/workspace/tutorial1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.398s
[INFO] Finished at: Fri Mar 1 11:46:08 PST 2013
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
Icon

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

Icon

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.xml

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:

                          TranslatorSource: DEFINED
                               TypeCoercer: REAL
                                URLEncoder: DEFINED
                         UpdateListenerHub: DEFINED
                    ValidateBindingFactory: DEFINED
             ValidationConstraintGenerator: DEFINED
                ValidationDecoratorFactory: DEFINED
                            ValidatorMacro: DEFINED
                        ValueEncoderSource: DEFINED

86.77% unrealized services (164/189)

Application 'app' (version 1.0-SNAPSHOT-DEV) startup time: 137 ms to build IoC Registry, 705 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.)

Icon

You should hit Control-C in the Terminal window to close down Jetty before continuing with the tutorial.