...
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.
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.
For the tutorial, I've used a fresh install of Eclipse and an empty workspace at /Users/Howard/Documents/workspace
Footnote |
---|
Yes, I'm on a Mac. Get one. |
From my workspace directory, I'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 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 org.apache.tapestry* com.example, artifact id tapestry-tutorial1, version 1.0-SNAPSHOT and we'll use orgcom.apache.tapestry5example.tutorial as the base package.
...
It will then prompt you to pick the archetype - choose quickstart Tapestry 5.2.4 Quickstart Project, enter the group id, artifact id, version and package when prompted.
Execute this in a temporary directory, it will create a sub-directory: tutorial1.
The first time you execute this command, Maven will spend quite a while downloading all kinds of JARs into your local repository, which can take a minute or more. Later, once all that is already available locally, the whole command executes in under a second.
Using 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:
Code Block | ||
---|---|---|
| ||
<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 in 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
|
Again, the first time, there's a dizzying number of downloads, but before you know it, the Jetty servlet container is up and running.
...
No Format |
---|
~/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
$
|
Note |
---|
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
.
Note | |||||
---|---|---|---|---|---|
| |||||
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:
Of course, adjust the |
Running the New Application in 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
|
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:
No Format |
---|
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
Code Block |
---|
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.
Loading the Project into Eclipse
Let's look at what Maven has generated for us. To do this, we're going to load the project inside Eclipse and continue from there.
Start by hitting Control-C in the Terminal window to close down Jetty..
Launch Eclipse and switch over to the Java Browser Perspective.
Right click inside the Projects view and select Import ...
Choose the "existing projects" option:
Now select the folder created by Maven:
When you click the Finish button, the project will be imported into the Eclipse workspace.
TODO: Picture of Java Browsing Perspective
Maven dictates the layout of the project:
...
!startpage.png! The date and time in the middle of the page proves that this is a live application. h2. Loading the Project into Eclipse Let's look at what Maven has generated for us. To do this, we're going to load the project inside Eclipse and continue from there. Start by hitting Control-C in the Terminal window to close down Jetty.. Launch Eclipse and switch over to the Java Browser Perspective. Right click inside the Projects view and select *Import ...* Choose the "existing projects" option: !eclipse-import.png! Now select the folder created by Maven: !eclipse-import-folder.png! When you click the Finish button, the project will be imported into the Eclipse workspace. *TODO: Picture of Java Browsing Perspective* Maven dictates the layout of the project: * Java source files under {{src/main/java}} * Web application files under {{src/main/webapp}} (including {{src/main/webapp/WEB-INF}}) |
...
* Java test sources under {{src/test/java |
...
}} * Non-code resources under {{src/main/resources}} and {{src/test/resources |
...
Info |
---|
Tapestry uses a number of }} {info} Tapestry uses a number of non-code resources, such as template files and message catalogs, which will ultimately be packaged into the WAR file alongside the Java classes. |
Investigating the Generated Artifacts
. {info} h2. Investigating the Generated Artifacts Let's look at what the archetype has created for us, starting with the web.xml file: |
...
{code | ||
:title | =src/main/webapp/WEB-INF/web.xml | }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>tutorial1 Tapestry 5 Application</display-name>
<context-param>
<!-- The only significant configuration for Tapestry 5, this informs Tapestry
of where to look for pages, components and mixins. -->
<param-name>tapestry.app-package</param-name>
<param-value>org.apache.tapestry5.tutorial</param-value>
</context-param>
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
|
...