Apache Tapestry – Quick Start


Apache Tapestry – Quick Start


”;


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-cli) > 
generatesources @ standalone-pom >>> 
[INFO]  
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) 
< generatesources @ standalone-pom <<< 
[INFO] 
[INFO] --- maven-archetype-plugin:2.4: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)

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 like 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 like 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 Application

To run the skeleton project, use the following command.

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

You get a screen like this,

[INFO] Scanning for projects... 
[INFO] 
[INFO] ---------------------------------------------------------------------------------
[INFO] Building Myapp Tapestry 5 Application 1.0-SNAPSHOT 
[INFO] ---------------------------------------------------------------------------------
........ 
........ 
........ 
Application ''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 [email protected]:8080 
[INFO] Started Jetty Server

As of now, we have created a basic Quick Start project in Tapestry. To view the running application 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 application and the default port of the application in development mode is 8080.

Using Eclipse

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

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

Step 1: Open Eclipse IDE

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

Open Eclipse

Now, choose Maven → Maven project option.

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

After selecting the Maven project, click Next and again click 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 click 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 click 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 click Finish button, now we have created the first skeleton application. 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, MyFirstApplication in your Package Explorer view.

Step 4: Run the application using Jetty server

You can use Maven to run Jetty directly. Right-click on the MyFirstApplication 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 click Run button.

Goals Option

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

Jetty Initialized

Step 5: Run in the web browser

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

https://loclhost:8080/MyFirstApplication

Run Web Browser

Step 6: Stop the Jetty server

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

Stop Server

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *