One of the cool things that keeps drawing me towards Tapestry is the goal to make it really easy and intuitive to work with. One of the goals that I remember hearing for Tapestry 5 was to make it that easy, that it would compete more w/ Grails & Rails and not so much w/ traditional Java Web app frameworks (e.g. Struts, Struts2, etc)
However, when I first took a look at Tapestry 5, I was a little disappointed by the six line Maven command that one had to type in when starting a new project (e.g. see http://tapestry.apache.org/tapestry5/tutorial1/first.html):
mvn archetype:create
-DarchetypeGroupId=org.apache.tapestry
-DarchetypeArtifactId=quickstart
-DgroupId=org.apache.tapestry
-DartifactId=tutorial1
-DpackageName=org.apache.tapestry.tutorial
Compare that with Grails:
grails create-app
Welcome to Grails 1.0 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/local/java/grails
Application name not specified. Please enter:
FooApp
---------------
[propertyfile] Updating property file: /home/polrtex/temp/FooApp/application.properties
Created Grails Application at /home/polrtex/temp/FooApp
It is true that one doesn't create an application all that often, and copy-and-pasting
these initial 5-6 lines would not be that big of a deal. However, for a newcomer, the Tapestry 5 experience has to be really smooth and starting a new app should be a breeze.
So, you would say, what does this have to do with NetBeans ?
Here it comes. As usual, NetBeans rocks everyone's socks, by lowering the entry barrier into starting an application. Here are the first steps (equivalent to the first two pages of the Tapestry tutorial : http://tapestry.apache.org/tapestry5/tutorial1/env.html). Here is what you need to do:
( Assuming that you already have a good install of NetBeans 6.1).
- Install the NetBeans Maven plugin by going into Tools -> Plugins . Type "maven" in the upper-left corner search box and install the plugin. The result should look something like this:
- Create a new Maven project
- Expand the "Archetypes from remote Maven repositories" and scroll down to find the Tapestry5 quickstart archetype . You might want to pay close attention to the description and select the latest archetypes (in my case, for 5.0.11)
- Now that you have the nice wizard, fill out the configuration attributes to specify the group id, the location of the project, the name of the project, etc.
- When you hit Finish, Maven will start downloading all the dependencies and setting up your project.
- Your new and shiny project is ready to go. Go into the project Properties and select your desired server to deploy to:
- Run the project from the project context menu and you're up and running !!!!
One very cool option that makes the Tapestry 5 setup almost identical to the Grails setup is the ability to run the application in Jetty by going to the command line and running:
mvn jetty:run
The upside of doing this is that after you run it, there is no deployment step. Tapestry supports reloading of the page templates as well as the page classes. As a result, whenever you make a change to a page, you can save it, refresh the browser and see the changes . Similarly, when you make a change to a class, compile it and the changes are immediately visible to the application. Such a setup really cuts down on waiting for the app to deploy.
So now, looking back a little bit, this setup is indeed very competitive w/ the Grails setup. In Grails, you would download the Grails distribution, and then would run the "grails create-app" command to create the new project. Grails would then prompt you for some properties (e.g. project name) and you're done. For Tapestry, it's quite similar; however, instead of downloading the Tapestry distribution, you would simply download Maven2 (or in the case of NetBeans, you would install the NetBeans plugin). Even better for Tapestry, if you already have Maven install, then starting a new app becomes a zero cost operation : you just specify the command line args (or better yet, use NetBeans to create the new app) and you're on your way, all dependencies already in place.
So, so far it's a tie between Grails and Tapestry. Grals vs Tapestry = 1:1
Enjoy your shiny and new Tapestry 5 app in NetBeans !!!
Hi,
ReplyDeleteI'd like to point out another problem with this setup that took me a lot of time and patience to figure out...
First of all, I had a problem using Jetty (with the jetty:run command that I added in the project properties under Actions), namely that the Tapestry's error handling page was somehow overriden by Jetty's default stacktrace dump. So this was a big annoyance.
Also, Netbeans does not automatically compile and deploy java sources, you have to redeploy (run) the application when they change.
But templates and other resources are copied directly to the target folder and you can view them immediately on the running server, so you only have to redeploy when you change the sources.
So I tried deploying on Tomcat, which worked, until I tried to redeploy (or rerun) the application while the server was still running. This produced an error java.io.FileNotFoundException: JAR entry log4j.properties not found when the server tried to undeploy the app that was still running. This also caused the redeploy to fail. After a server restart, the app would run normally, but this is too time consuming.
The root cause for this, after a few hours of googling and pulling my hair, is that the tapestry5 quickstart maven archetype contains a configuration option that packages the sources as a .jar file and puts them in the lib folder for the target.
The problem is that the Java runtime caches ZIP file indexes and this causes a file not found error when the underlying jar file is changed.
Editing the <archiveClasses> option in the pom.xml file in the root of your project from true to false makes the project deploy the application normally, as an exploded war.
Note that you probably have to do a clean afterwards or manually delete the project's .jar file in the target/project-name/WEB-INF/lib directory.
Hi,
ReplyDeleteI followed this article, but for some reason my templates for components do not reload. Neither in Glassfish nor in Jetty via mvn jetty:run. Only page templates show changes immediately.
Please help me!
Ciao Frank
dirk,
ReplyDeletethere are two things to mention here :
1. First double check that your "archiveClasses" option in the pom is set to "false". As dane pointed out in a previous comment, the default setting for the maven project is to package up the project into a war (which might cause you other problems)
2. The secondary (and probably more relevant to you) problem is that the Maven project type doesn't automatically compile your classes and move them into the maven build directory when you make the changes. Thus (unfortunately), when you make a change to your classes, you'd still need to run a build in NetBeans to have the classes copied out to the target directory. For some reason, I recall that the class reloading used to work for me in Jetty and in Glassfish, I had to do the build.
Here's the skinny on this issue :
ReplyDelete1. If you place your .tml pages inside of your web app context directory (that is, under "Web Pages" in NetBeans), the IDE will automatically copy the changed files into the Maven target directory and you will see immediate feedback in the running app.
2. If your .tml files are at the root of the resource tree (that is, under "Other Sources/resources in NetBeans), their changes will not be picked up automatically.
3. Your changes to java classes will not be picked up automatically. Whenever you want to see the changes to your java page classes (and changes to the templates in the resource tree), then you need to run the project (which redeploys it) and voilla.. the stuff is there.
This is less than optimal, there are a couple of BugZilla issues in NetBeans to address these, in the meantime use these instructions to work w/ T5 and NetBeans.
Alex,
ReplyDeletethanks for the quick response. You' re right, having to rerun the app after every single change is less than optimal. But you mentioned earlier that 'Tapestry supports reloading of the page templates as well as the page classes'. This doesn't seem to be true.
Is there any way to trigger the build automatically?
Ciao,
Dirk
Hi Alex.
ReplyDeleteI'm from Uruguay and i followed this article to try tapestry 5 on netbeans 6.5. I deploing the application over GlassFish V2, and all working fine. But i need use layout component to make my application web, y followed many articles but can not works well, the content of the layout component is not shown, only the content of the page is shown and gives no error.
Any comments or solution?
Thanks for this article and sorry for my english traduction.
There are a couple of fixes in the NB Maven plugin coming up in the 6.7 release (they'll be in the daily builds in a day or two), that make using T5 & NetBeans just so pleasurable (w/ the live class reloading working beautifuly w/ Jetty). Stay tuned for a blog post on that !
ReplyDeleteHi,
ReplyDeleteI'm at step 3 using NetBeans 6.7 and I can't find the T5 quickstart archetype anywhere. Help!
Thanks in advance,
Anthony
I wrote the first CD-ROM application. I started with nothing but a device driver that returned 1 - 8 2k sectors off a CD and the Lattice C compiler. I used that to bootstrap a multivolume file system and wrote a DOS interrupt handler to give read and lseek access to C programs. That was easier to me than the horde of non-deterministic, ever changing, version incompatible stuff with all kinds of odd names that are supposed to mean something that comes down the Apache pike. Really, after trying maybe five different methods to install Tapestry 5 with Netbeans, every method had some kind of fatal error. "To use the cool templetized features, required with Shakti 2.7, Mocumbro 7.7, V 7.1 of Fandangular will need you to move your 30,000 lines of Java to 1.6! Soon we will be compatible with the systems you actually use until it no longer works!" is about par for the course. I am like some 70 year-old trying to understand why I should twitter on a cell phone where I can't even see the tiny little keys or operate them with my arthritic fingers.
ReplyDeletein step 3, I dont see the Tapestry Archtype in the list. What do I do to get Tapestry archtype? Thanks
ReplyDeletehi,
ReplyDeletesame for me ... no Tapestry archetype at the 3rd Step
Thx