English 中文(简体)
Apache Tapestry - Quick Start
  • 时间:2024-11-03

Apache Tapestry - Quick Start


Previous Page Next Page  

After Tapestry installation, let us create a new initial project using Maven as shown below −

$ mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org

You could see the response as shown below −

[INFO] Scanning for projects... 
[INFO] 
[INFO] --------------------------------------------------------------------------------- 
[INFO] Building Maven Stub Project (No POM) 1 
[INFO] ---------------------------------------------------------------------------------
[INFO] 
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cp) > 
generatesources @ standalone-pom >>> 
[INFO]  
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cp) 
< generatesources @ standalone-pom <<< 
[INFO] 
[INFO] --- maven-archetype-plugin:2.4:generate (default-cp) @ 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)

After Maven building all the operations, choose archetype to create Tapestry 5 QuickStart project as follows −

Choose archetype

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1

Now you will get a response pke what is shown below −

Choose org.apache.tapestry:quickstart version: 
1: 5.0.19
2: 5.1.0.5 
3: 5.2.6 
4: 5.3.7 
5: 5.4.1 

Extract the QuickStart version number as follows −

Choose a number: 5: 5

Here, the QuickStart project takes the version for the option 5, “5.4.1”. Now, Tapestry archetype asks the following information one by one as follows −

    5.1 groupId − Define value for property groupId : : com.example

    5.2 artifactId − Define value for property artifactId : : Myapp

    5.3 version − Define value for property version : 1.0-SNAPSHOT: :

    5.4 package name − Define value for property package : com.example: : com.example.Myapp

Now your screen asks confirmation from you −

Confirm properties configuration −

    groupId − com.example

    artifactId − Myapp

    version − 1.0-SNAPSHOT

    package − com.example.Myapp

Verify all the properties and confirm the changes using the option shown below −

 Y: : Y 

You would see the screen pke the one shown below.

[INFO] ---------------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: quickstart:5.4.1 
[INFO] ---------------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.example 
[INFO] Parameter: artifactId, Value: Myapp 
[INFO] Parameter: version, Value: 1.0-SNAPSHOT 
[INFO] Parameter: package, Value: com.example.Myapp 
[INFO] Parameter: packageInPathFormat, Value: com/example/Myapp 
[INFO] Parameter: package, Value: com.example.Myapp 
[INFO] Parameter: version, Value: 1.0-SNAPSHOT 
[INFO] Parameter: groupId, Value: com.example 
[INFO] Parameter: artifactId, Value: Myapp 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/test/java 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/main/webapp 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/main/resources/com/
example/Myapp 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/test/resource 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/test/conf 
[WARNING] Don t override file /Users/workspace/tapestry/Myapp/src/site 
[INFO] project created from Archetype in dir: /Users/workspace/tapestry/Myapp 
[INFO] --------------------------------------------------------------------------------- 
[INFO] BUILD SUCCESS 
[INFO] --------------------------------------------------------------------------------- 
[INFO] Total time: 11:28 min 
[INFO] Finished at: 2016-09-14T00:47:23+05:30 
[INFO] Final Memory: 14M/142M 
[INFO] ---------------------------------------------------------------------------------

Here, you have successfully built the Tapestry Quick Start project. Move to the location of the newly created Myapp directory with the following command and start coding.

cd Myapp 

Run Apppcation

To run the skeleton project, use the following command.

mvn jetty:run -Dtapestry.execution-mode=development

You get a screen pke this,

[INFO] Scanning for projects... 
[INFO] 
[INFO] ---------------------------------------------------------------------------------
[INFO] Building Myapp Tapestry 5 Apppcation 1.0-SNAPSHOT 
[INFO] ---------------------------------------------------------------------------------
........ 
........ 
........ 
Apppcation  app  (version 1.0-SNAPSHOT-DEV) startup time: 346 ms to build IoC 
Registry, 1,246 ms overall.  
 ______                  __             ____ 
/_  __/__ ____  ___ ___ / /_______ __  / __/ 
 / / / _ `/ _ / -_|_-</ __/ __/ // / /__   
/_/  \_,_/ .__/\__/___/\__/_/  \_, / /____/ 
        /_/                   /___/  5.4.1 (development mode)   
[INFO] Started SelectChannelConnector@0.0.0.0:8080 
[INFO] Started Jetty Server

As of now, we have created a basic Quick Start project in Tapestry. To view the running apppcation in the web browser, just type the following URL in the address bar and press enter −

https://localhost:8080/myapp

Here, myapp is the name of the apppcation and the default port of the apppcation in development mode is 8080.

Using Ecppse

In the previous chapter, we discussed about how to create a Tapestry Quick Start apppcation in CLI. This chapter explains about creating a skeleton apppcation in Ecppse IDE.

Let us use a Maven archetype to create skeleton apppcation. To configure a new apppcation, you can follow the steps given below.

Step 1: Open Ecppse IDE

Open your Ecppse and choose File → New → Project… → option as shown in the following screenshot.

Open Ecppse

Now, choose Maven → Maven project option.

Note − If Maven is not configured then configure and create a project.

After selecting the Maven project, cpck Next and again cpck the Next button.

Maven Project

After that, you will get a screen where you should choose the configure option. Once it is configured, you will get the following screen.

Configure Option

Step 2: Catalog Configuration

After the first step is done, you should cpck on Add Remote Catalog. Then add the following changes as shown in the following screenshot.

Remote Catalog

Now, Apache Tapestry Catalog is added. Then, choose filter option org.apache.tapestry quickstart 5.4.1 as shown below.

Added Catalog

Then cpck Next and the following screen will appear.

Group Id Field

Step 3: Configure GroupId, ArtifactId, version and package

Add the following changes to the Tapestry Catalog configuration.

Changes Configuration

Then cpck Finish button, now we have created the first skeleton apppcation. The first time you use Maven, project creation may take a while as Maven downloads many JAR dependencies for Maven, Jetty and Tapestry. After Maven finishes, you ll see a new directory, MyFirstApppcation in your Package Explorer view.

Step 4: Run the apppcation using Jetty server

You can use Maven to run Jetty directly. Right-cpck on the MyFirstApppcation project in your Package Explorer view and select Run As → Maven Build… you will the screen shown below.

Jetty Server

In the configuration dialog box, enter goals option as “jetty:run” then cpck Run button.

Goals Option

Once Jetty is initiapzed, you ll see the following screen in your console.

Jetty Initiapzed

Step 5: Run in the web browser

Type the following URL to run the apppcation in a web browser –

https://loclhost:8080/MyFirstApppcation

Run Web Browser

Step 6: Stop the Jetty server

To stop the Jetty server, cpck the red square icon in your console as shown below.

Stop Server Advertisements