Wiki Markup |
---|
{scrollbar} |
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 /Usersusers/joeuser/workspace
. You may need to adjust a few things for other operating systems or local paths.
Using the Quickstart Archetype
From our workspace directoryEclipse, 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
|
Info |
---|
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. |
...
No Format |
---|
$ 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] ------------------------------------------------------------------------
|
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
.
Info | |||||||
---|---|---|---|---|---|---|---|
| |||||||
If you are behind a firewall/proxy, before running any "mvn" commandsperforming any Maven downloads, you will may need to configure your proxy settings in your Maven settings.xml file (typically ~/.m2/settings.xml). Here is an example:
Of course, adjust the |
In Eclipse, go to File > New > Project... > Maven > Maven Project
Then click Next, Next (again), 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.
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.
Info |
---|
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.
Change into the newly created directory, and execute the command:
Code Block | ||
---|---|---|
| ||
mvn jetty:run
|
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:
No Format |
---|
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: 13787 ms to build IoC Registry, 705376 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 |
...
Warning |
---|
You should hit Control-C in the Terminal window to close down Jetty before continuing with the tutorial. |
Wiki Markup |
---|
{scrollbar} |
Info |
---|
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. |