...
Scrollbar |
---|
...
Using the Quickstart Archetype
First, let's Before we can get down to the fun, we have to create an empty application. Tapestry uses provides 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 workMaven archetype (a project template) to make this easy.
For the tutorial, we're using a fresh install of Eclipse and an empty workspace at /Usersusers/Howard/Documentsjoeuser/workspace
Footnote |
---|
Yes, Howard is on a Mac. Get one. |
Using the Quickstart Archetype
From EclipseFrom our workspace directory, we'll use a Maven archetype 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:
Code Block |
---|
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.
...
Maven
...
Info |
---|
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
.
...
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 in the .m2 subdirectory of your home directory, ~/.m2 or C:\users\joeuser\.m2). Here is an example
...
(but check with your network administrator for the names and numbers you should use here).
Code Block | ||||
---|---|---|---|---|
| ||||
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>myProxyServer.com</host>
<port>8080<<port>3128</port> <username>joeuser</username> <password>myPassword</password> <nonProxyHosts></nonProxyHosts> </proxy> </proxies> <localRepository>C:/Documents and Settings Users/joeuser/.m2/repository</localRepository> </settings> |
Of course, adjust the localRepository
element to match the correct path for your computer.
Create Project
Okay, let's get started creating our new project.
Tip |
---|
The instructions below use Eclipse's New Project wizard to create the project from a Maven archetype. If you'd rather use the mvn command line, see the Getting Started instructions, then skip to Creating The Skeleton Application page. |
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 below:
As shown above, enter "http://tapestry.apache.org" in the Catalog File field, and "Apache Tapestry" in the Description field.
Info |
---|
If you want to try an unreleased (alpha or beta) version of Tapestry, use the https://repository.apache.org/content/repositories/staging archetype catalog file instead. |
Click OK, then OK again.
On the Select an Archetype dialog (shown below), select the newly-added Apache Tapestry catalog, then select the "quickstart" artifact from the list and click Next.
...
Note: Screenshots in this tutorial may show different (either newer or older) versions of Tapestry than you may see.
Fill in the Group Id, Artifact Id, Version and Package as follows:
then click Finish.
Info |
---|
The first time you use Maven, project creation may take a while as Maven downloads a large number of JAR dependencies for Maven, Jetty and Tapestry. 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, tutorial1, 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.
Change into the newly created directory, and execute the command:
...
Right-click on the tutorial1
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:
Tapestry runs best with a couple of additional options; click the "JRE" tab and enter the following VM Arguments:
Pre |
---|
-Xmx600m -Dtapestry.execution-mode=development |
Here's how it looks:
Finally, 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:
...
Note the red square icon above. Later on you'll use that icon to stop Jetty before restarting the app.
You can now open a web browser to http://localhost:8080/tutorial1/ to see the running application:
NOTE: Your screen may look very different depending on the version of Tapestry you are using!
The date and time in the middle of the page
...
shows that this is a live application.
This is a complete little applicationweb app; 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 several 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.. Footnote
Warning |
---|
You should hit Control-C in the Terminal window to close down Jetty before continuing with the tutorial. |
Footnotes Display |
---|
...
)
Next: Exploring the Project
Scrollbar