Wednesday, December 17, 2008

Task 1 - Create a skeleton Tapestry 5 project and run it.

Fire up Eclipse Ganymede and choose Java perspective. Make sure the eclipse is started up with JDK not JRE.

Select File/New/Other… from the Eclipse menu. In the dialog type maven in the Wizard's input field to reduce the number of wizards in the list. Select Maven Project.


In the New Maven Project dialog that appears next just click Next. Don’t get distracted by other options for now.


After clicking Next, you will see something similar like the image bellow.


In short - there are numerous so called archetypes (maven terminology for project templates) in the list which are identified by GroupId, ArtifactId and Version. Archetypes are “gathered” in catalogs and one of them is Nexus Indexer which includes all archetypes from the central maven repository.

If you don’t see any artifacts, then you don’t have central index downloaded or you haven’t chosen to include an optional component Maven Central repository index while installing m2eclipse plugin.

If you do see the artifacts, then you can skip the next two screenshots.

Check Software Updates and Add-ons in Help/Software updates… menu in Eclipse to confirm you have all the necessary components installed.

If you don’t have Maven Central repository index in the list of Installed Software, then select Available Software tab and install it by selecting this/these module(s) under Maven Integration for Eclipse Update Site.

To automatically download Nexus index (which includes Tapestry 5 archetypes) at Eclipse startup check Download repository index updates on startup in the Preferences.


Now let's continue. We are looking for Tapestry 5 archetype, so type tapestry in the Filter input field.


Select quickstart archetype, at present (December 2008) the version 5.0.18 is available. Click Next.

Now the New Maven Project Wizard displays a dialog which asks us about the name of the project. Name is not the right term in Maven world, but we will not go too deeply into theory for now, let’s just type org.driving for the GroupId and school for ArtifactId. Leave the Version as is.


Click Finish.

After a few moments you should see something very similar to the image below in the Package Explorer.

If you don’t have a Console View in your Java Perspective, please add it (Window/Show View/Console). Choose Maven Console.


Let’s stay focused. The task is to create a basic Tapestry 5 skeleton application and run it. Let’s do that!

Select Run Configurations… from the Run Menu Command.


This will open up the Run Configurations dialog. Locate and select Maven Build and then press the New button.


Now fill in the missing blanks in the next dialog. Name this Run Configuration with something meaningful, like Run Traffic School. The fill in the Base Directory by clicking the Browse Workspace button and selecting the school project. Type jetty:run for the Goal input field. Then click Run and wait for Maven to download all the necessary artifacts. This can take some time the first time, but the next time the Jetty will launch very quickly.


If all goes well, you should see something like this in the Maven Console:


Open your browser and type http://localhost:8080/school

You should see


You can click the refresh link and see the time changes – just to prove it works. You can stop the Jetty server by clicking on the red square in the Maven Console. This ends this task.

You learned how to create a new Tapestry 5 skeleton project by running New Maven Project wizard and how to run the Tapestry 5 web application by creating a maven run configuration.

Alternative approaches

You can create a Tapestry 5 skeleton project by running
mvn archetype:create
-DarchetypeGroupId=org.apache.tapestry
-DarchetypeArtifactId=quickstart
-DgroupId=org.driving
-DartifactId=school
-DpackageName=org.driving.school

You can run the application with

mvn jetty:run or with mvn tomcat:run

You can also run the web application with WTP (Web Tools Project) by right clicking on a project and selecting Run As / Run on Server.

If you haven’t defined a server yet or even not downloaded one, then you have some more work to do. Choose the server (Tomcat 6.0 for example).


In the next step choose the directory of the Tomcat you have downloaded and unzipped to.


After clicking on Next, a dialog appears which shows which projects can be run on this Tomcat server.


Our project is already configured, so just click Finish. The Tapestry 5 project will be launched and first page displayed in the embedded browser inside Eclipse.


Running with Tomcat with WTP causes the Tomcat container to reload the context (by default) on any file change in the context path. This is sometimes not desirable as it hides the jewel of Tapestry – live class reloading. To be discussed in the next task.

Reblog this post [with Zemanta]

13 comments:

  1. Just a note:
    in my eclipse, at the step 3, the archetypes are not loaded from nexus indexer. I had to add the tapestry archetype manually, using this as the url:

    http://repo1.maven.org/maven2/

    If you can add this to your post, it will help someone with a similar problem.

    ReplyDelete
  2. Hi Lotif,

    When you startup Eclipse, does something similar to this

    3.10.08 7:56:52 CEST: Error on adding indexing context central; D:\dev\wspace_mvn\.metadata\.plugins\org.maven.ide.eclipse\nexus\central\_9.fdt (The system cannot find the file specified)

    prints out in the console?

    ReplyDelete
  3. No, it prints nothing...
    but your hint to add the other maven plugins works very well. Thanks!

    ReplyDelete
  4. It came to my attention that if running jetty:run from Eclipse, web applicaton fails to start sometimes (if jetty artifacts are not already in your local repository under .m2).

    Try running mvn jetty:run from the command line first.

    It seems m2eclipse has trouble downloading artifacts under certain conditions which I can not identify.

    ReplyDelete
  5. Hi Borut,

    Seems like maven obliges your ptoject to compile using the 1.5 compiler. Do you have any experience using this build strategy + Java 6?

    Thanks.

    ReplyDelete
  6. Hello Lotif,

    Maven (2.0.9), or better - the compiler plugin (2.0.2), by default compiles your code with source setting 1.3 and target setting 1.1.

    Look at http://maven.apache.org/plugins/maven-compiler-plugin/

    Then if you want to compile with JDK 6, you have to tell the compiler plugin to use it. Look at http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

    I am using the approach descibed at the above page and it works ok.

    ReplyDelete
  7. Also thought that you can also have an empty artifacts list if you've just installed the m2eclipse plugin and it is still downloading the initial index - check your for the little background progress indicator in the bottom right (or where-ever it hides in your install).

    ReplyDelete
  8. Hello all,

    I have been trying to deploy my Tapestry 5 Web application in Weblogic 9.2.

    Don't seem to get any sort of help for issues related to Tapestry 5 + Weblogic 9.2 deployment.

    Als, we do not see any deployment notes in the apache's website for this issue.

    Can anyone please point me to a good FAQ which wil help me deploy my Tap 5 app in Weblogic 9.2 ?

    ReplyDelete
  9. Thanks much for the great walkthrough! I linked to you from my blog post as well, and I plan to read the other 6 steps you put together. Thanks for taking the time to do this - it saved me quite a bit of time getting started with Tapestry.

    (The aforementioned blog entry is here: http://independentindetroit.blogspot.com/)

    ReplyDelete
  10. Hi, I already have a defined Tomcat 6 instance, but when I select "Run As, I don't have the "Run on Server" option, like eclipse don't recognize the app as web app. Any idea about the problem. Thanks for your posts.

    ReplyDelete
  11. Hi, great tutorial! My question: Is it possible to use the "live class (and template) reloading" feature from tapestry in WTP with tomcat 6 or 7? I tried it for a while, but it did not work properly.

    ReplyDelete
  12. Hai All i'm very much new to Apache Tapestry5 and i'm using Eclipse with maven plugin-3.0.3 & Jetty 6.1.26 ..the problem is when ever i try to run my application as
    Run as-->Run configuration-->then selecting Project --->
    Run.i'm getting as HTTP ERROR-503 .and in my console i'm getting as............


    Running Jetty 6.1.26
    2011-12-17 14:41:29.615:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
    ParentLoaderPriority enabled
    Context path:/tutorial1
    ProjectClassLoader: entry=/home/admin/tutorial1/target/classes
    Starting scanner at interval of 5 seconds.
    2011-12-17 14:41:29.702:INFO::jetty-6.1.26
    2011-12-17 14:41:30.050:WARN::EXCEPTION
    java.lang.ClassNotFoundException: org.apache.tapestry5.TapestryFilter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)


    Please help me out..as i'm struck in mid way..

    Thanqs in advance

    ReplyDelete
  13. First confirm you can run the basic tapestry archetype from the command line with mvn jetty:run, that is, without using Eclipse.

    ReplyDelete