Tips
These tips cover JumpStart 5.4.n.
Some other excellent resources are
the Tapestry 5 How-To Page,
and the Tapestry User
mailing list
which is archived and searchable at
nabble and
gmane.
Also, the book Tapestry 5: Building Web Applications by Alexander Kolesnikov,
although it is getting very out of date.
Contents
JVM options. Editing .tml files. Use Loom. Debugging. Testing: WAR or EAR? Unit tests. Integration tests. |
The database. Viewing and editing data. Logging SQL and Hibernate. Altering the database schema. Rebuilding the database and schema. MySQL. Other database brands. |
Creating a fresh project. Other servers: GlassFish 2.1.1 Tomcat 5.5 or 6.0 JBoss 5.0.1 JBoss 6.0.0 JBoss 6.1.0 Portability |
- When running Jetty we already set several JVM options, including -Dtapestry.production-mode=false and -Dhibernate.hbm2ddl.auto=update
Here are some to consider:-Dtapestry.production-mode=false Tells the Tapestry ExceptionReport page to display full details of the exception, which is great during development. When set to true (which is the default since T5.0.10), Tapestry's ExceptionReport page will display an abbreviated report so as to avoid disclosing details of your application's internals. See Configuring Tapestry. -Dtapestry.compress-whitespace=false Tells Tapestry not to compress whitespace as it generates a page from a template. Makes the generated page source much easier to read eg. when you tell your browser to display the page source. See Configuring Tapestry. -Dhibernate.hbm2ddl.auto=update Necessary for JumpStart initially, and great during development, but
NOT RECOMMENDED IN A PRODUCTION ENVIRONMENT because data can be lost. Tells Hibernate to automatically bring the database structure into line with the app's entity definitions at every restart. See hibernate optional configuration properties.-Xms192m -Xmx192m Gives more memory for the heap, avoiding "out of memory" errors. See JVM options. -XX:MaxNewSize=96m -XX:MaxPermSize=96m Gives more Perm Gen memory. If you encounter Perm Gen memory errors then consider this or an even higher setting. See JVM options
EDITING .tml FILES
Any HTML editor will do. In Eclipse, associate .tml files with the HTML editor:
- choose Window > Preferences > General > Editors > File Associations (or in OS X, choose Eclipse > Preferences > General > Editors > File Associations), and
- in File types, add *.tml.
- in Associated Editors, add HTML Editor, Web Page Editor, Web Browser, and Text Editor,
- click OK.
- choose Window > Preferences > General > Content Types (or in OS X, choose Eclipse > Preferences > General > Content Types), and
- in Content types, choose Text > HTML,
- in File associations, add *.tml.
- click OK.
USE LOOM
Loom is a delight to use.
It's an Eclipse plug-in that allows you to switch between a template and a java file by using a keyboard shortcut (Ctrl+Alt+X).
To install it:
- Open the Eclipse update facility (Help > Install New Software).
- Click Add.... The Add Site dialog will appear.
- Set Name to Loom.
- Set Location to http://digitalsoul.org/loom/update-site. Click OK.
- Choose the site from the list (I use the stable release, 1.0.2) and click Next >, then Next >, then read the license text, accept it, and click Finish.
- Loom will be installed.
- Choose Window > Preferences > Loom (or in OS X, choose Eclipse > Preferences > Loom), and
- Select .tml and click Apply.
DEBUGGING
By default, the project automatically builds a WAR file for testing with Jetty.
It's in a directory called collapsed/ and its format is "collapsed EAR", which is nice and simple.
It's automatically kept up-to-date by a builder called collapser which you can see by displaying the project's properties and choosing Builders.
To debug any part of JumpStart while running it in Eclipse (with RunJetty), use Run > Debug Configurations... instead of Run > Run Configurations....
Eclipse will then stop at breakpoints, display variables, enable single-stepping, etc.
Source not found. At a breakpoint, Eclipse might display Source not found.
Click Edit Source Lookup Path... > Add... > Java Project, select your jumpstart project and click OK, then OK again.
Tapestry source. To read, step through, or debug Tapestry source you'll first need to download it from
Tapestry 5 Download. Then unzip/untar/whatever it into your development directory, eg. /devel/tapestry-src-5.2.6.
In Eclipse, choose File > Java Project, deselect Use default location, click Browse... and choose the Tapestry source folder.
If Eclipse now complains that the project "overlaps the location of another project", re-select Use default location. Click Finish.
The Tapestry source project will not compile, but that doesn't matter. Now you can find components and put breakpoints in them.
As always at the first breakpoint, Eclipse might display Source not found.
Click Edit Source Lookup Path... > Add... > Java Project, select the Tapestry source project and click OK, then OK again.
TESTING: WAR OR EAR?
By default, the project automatically builds a WAR file for testing with Jetty.
It's in a directory called collapsed/ and its format is "collapsed EAR", which is nice and simple.
It's automatically kept up-to-date by a builder called collapser which you can see by displaying the project's properties and choosing Builders.
If you prefer, the project can automatically build an "exploded EAR" file which is
readable by JBoss (and GlassFish?) and, for that matter, Jetty. It goes in a directory called "exploded/" and it can be automatically kept up-to-date by a builder called
exploder which you can see by displaying the project's properties and choosing Builders.
Just select exploder and, if you like, de-select collapser .
Set collapsed and/or exploded directory to derived. In Eclipse, right-click on the collapsed or exploded directory,
choose Properties, and tick the derived checkbox. Then click OK.
To run the collapsed EAR in Jetty, follow the instructions on the installation page.
To run the exploded EAR with JBoss, configure your JBoss server to scan the exploded/ directory, which you can do by
editing the server's conf/bootstrap/profile.xml file to add the exploded/ directory to the "VFSDeploymentScanner" bean, eg.
<!-- Scan for applications -->
<bean name="VFSDeploymentScanner" class="org.jboss.system.server.profileservice.VFSDeploymentScannerImpl">
<property name="profileService">
UNIT TESTS
JumpStart has a simple unit test suite in the business tier. Its name is BusinessUnitTestSuite. You can run it as a JUnit Test in Eclipse, or in Ant.
Run with Ant
- Run the Ant target clean-compile-test in the project's build.xml file.
- If you get an error about JAVA_HOME, read this. Use a JDK 1.5 tools.jar.
Run as JUnit Test in Eclipse
- Here are the instructions for unit test in eclipse
INTEGRATION TESTS
JumpStart's integration test suite checks that the business layer is operating correctly and that it is reporting all possible exceptions correctly.
Its name is BusinessIntegrationTestSuite.
Run as JUnit Test in Eclipse
- Here are the instructions for integration test in eclipse with embedded OpenEJB.
THE DATABASE
JumpStart session beans specify to use a persistence unit called jumpstart.
The persistence.xml file maps jumpstart to 1 or 2 data sources. Their JNDI names are java:/JumpStartDS and java:/JumpStartDSUnmanaged.
By default, OpenEJB overrides the data sources to its own which use the Hypersonic database in OpenEJB's data/hsqldb/ directory. This is handy.
To override this behaviour, supply an openejb.xml configuration file. You can see this being done in other servers.
For running in JBoss, the build script puts a configuration file called jumpstart-hsqldb-ds.xml in deploy/.
The file maps the JNDI names to an HSQLDB database.
VIEWING AND EDITING DATA
Hypersonic provides a handy GUI tool for viewing the database and executing SQL requests, the HSQL Database Manager. To use it:
- In the project's data_util.properties file, set the properties hsqldb.data.dir and hsqldb.jar.dir.
- With the data_util.xml file in the Ant view, run the target start-hsqldb-manager.
- In a few moments the HSQL Database Manager will start up.
- Point your web browser at the JMX console, eg. http://localhost:8080/jmx-console/.
- Click on database=localDB,service=Hypersonic.
- Find the section labelled void startDatabaseManager().
- Click on Invoke.
- In a few moments the HSQL Database Manager will start up. Note that it will start on the machine that JBoss is running.
LOGGING SQL AND HIBERNATE
Logging is configured by log4j.properties in business/src/dev/conf/.
-
log4j.category.org.hibernate.SQL=DEBUG
-
log4j.category.org.hibernate=DEBUG
You will also have to change the logging threshold of the CONSOLE appender from INFO to DEBUG. Alternatively, to avoid cluttering up the console log, create a new appender definition called, say, HIBERNATE, by copying one of the appender definitions called FILE (look for appender name="FILE"). Then define your new category like this:
-
log4j.category.org.hibernate=DEBUG, HIBERNATE
ALTERING THE DATABASE SCHEMA
The schema is defined by the classes containing the @Entity annotation.
By default, JumpStart will automatically create/update the database schema
to match. That includes creating tables and constraints when necessary.
This behaviour is controlled by the
hibernate.hbm2ddl.auto
property in persistence.xml.
Unfortunately, you can't just override the behaviour at runtime eg. with some settings in a properties file in the conf/ directory. It seems that either Hibernate (or the EJB3 spec?) requires the Hibernate settings to be specified in persistence.xml, and the EJB3 spec requires persistence.xml to be inside the ear file. This seems like an oversight, but in fact is probably just right because it forces you to make your test environment match your production environment.
REBUILDING THE DATABASE SCHEMA
Some changes don't seem to propagate to the database schema, for example switching a field from nullable=false to nullable=true.
So at times you may decide to rebuild the schema.
- Backup the data This is optional, but the next step will delete all your data. The initial JumpStart data is re-loadable in step 4.
- Drop the tables Use JumpStart's drop_tables.sql script, or modify it to suit. If your database is JBoss's Hypersonic, use the HSQL Database Manager
- Create the tables Either run the ant target touch-exploded-ear in JumpStart's build.xml, or restart the server. See Altering the database schema above for details.
- Restore the data or re-load the initial data If you backed up the data in step 1, then you can restore it now. Alternatively, re-load the initial data with JumpStart's initial_data.sql script.
MYSQL
To use MySQL with JumpStart, please upgrade to JumpStart 5.10.1 or later.
OTHER DATABASE BRANDS
To use database brands other than HSQLDB or Derby, please see the Tips for JumpStart 5.10.
CREATING A FRESH PROJECT
Choose a project name, root package name, etc., then edit the values in tools/tools.properties .
Drag tools/tools.xml to the Ant view and run the target create-fresh-project.
A new project will have been created with an Index page, Login page, the User and UserPassword entities
and a few pages to maintain them.
Then do much the same as you did from Step 2 onwards of Installation.
OTHER SERVERS
The following links show how to prepare other servers and how to build, deploy and test JumpStart on them:
Tomcat 7.0 support may be possible when OpenEJB updates their Tomcat installer, openejb.war.
JBoss 7.0 support has not been worked on yet.
PORTABILITY
The package produced by a build is tailored to a particular server type, persistence provider, and database server type.
So can a package be moved between servers? Yes, but only if they have the same...
- server type (eg. glassfish 2.1.1, tomcat 5.5 or 6.0, jboss 5.0.1 or 6.0.0 or 6.1.0) AND
- persistence provider (eg. hibernate) AND
- database server type (eg. hsqldb, mysql, derby).
- web.xml is different for GlassFish because GlassFish requires ejb-local-refs elements.
The build finds this alternative web.xml from web/src/main/java/jumpstart/web/WEB-INF/ - persistence.xml varies based on the combination of deployment server type, persistence provider, and database server type.
The build finds these alternatives in business/src/main/resources/persistence-descriptor/ - The package is an EAR file for GlassFish and JBoss.
- The package is a WAR file for Jetty and Tomcat,
in "collapsed EAR" format.