Tips
These tips cover JumpStart 7.0.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, these books.
Contents
- 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.-Xmx192m Gives more memory for the heap, avoiding "out of memory" errors. See JVM options.
EDITING .tml FILES
Any HTML editor will do. In Eclipse, first check you have the right web tools installed:
- choose Help > Install New Software... > already installed > Installed Software
- Do you see Eclipse Web Developer Tools and Web Page Editor?
- If no, do you see Eclipse IDE for Java EE Developers and does it contain Java EE IDE Feature and does that contain Eclipse Web Developer Tools and Web Page Editor?
- If no, then install Eclipse Web Developer Tools and Web Page Editor:
- choose Help > Install New Software...
- set Work with: to --All Available Sites--
- set the filter text to web
- drill into the results, choose Eclipse Web Developer Tools and Web Page Editor.
- click Finish.
- Eclipse may ask whether it can restart. Say yes.
- You have the right web tools installed.
- 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.
ADD ECLIPSE INTEGRATION FOR TAPESTRY5
Eclipse Integration for Tapestry5 is a delight to use.
It's an Eclipse plug-in, and my favourite feature is that you can switch between a template and a java file by using a keyboard shortcut (Ctrl+R).
- In Eclipse: Help > Eclipse Marketplace... > Search, then find tapestry. Install Eclipse Integration for Tapestry5.
- Modify the keyboard shortcuts because they conflict with, and get messed by, some others:
In Preferences... > General > Keys, filter with tapestry, and:
- Change Quick Switch within Tapestry Context from Cmd+; to Ctrl+;.
- Change Switch Tapestry Design/Code from Cmd+R to Ctrl+R.
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.4.3.
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.
In the past, JumpStart was also able to build an "exploded EAR" file which is
readable by WildFly (and GlassFish?) and, for that matter, Jetty. This facility is no longer supported in JumpStart but the source, exploder.xml,
is still present in the project for those who find it useful.
Set the collapsed directory to derived. In Eclipse, right-click on the collapsed 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.
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.
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 HyperSQL 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 WildFly, the build script puts a configuration file called jumpstart-hsqldb-ds.xml in deploy/.
The file maps the JNDI names to an H2 database.
VIEWING AND EDITING DATA
HyperSQL 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 property database.url.
- 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.
LOGGING SQL AND HIBERNATE
Logging is configured by log4j.properties in business/src/test/conf/.
-
log4j.logger.org.hibernate.SQL=DEBUG
-
log4j.logger.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 property
hibernate.hbm2ddl.auto
which we set at runtime via system properties, eg. -Dhibernate.hbm2ddl.auto=validate in production
and perhaps -Dhibernate.hbm2ddl.auto=update during initial development.
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 WildFly's H2, see Using JumpStart in WildFly.
- Create the tables 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
JumpStart has been tested with HSQLDB, H2, Derby, and MySQL. HSQLDB and H2 are very convenient but,
in general, MySQL returns better exception information for JumpStart to work with.
For example, a simple duplicate key situation in HSQLDB can result in a "failed JDBC batch" exception and no further information.
JumpStart's class HibernatePersistenceExceptionInterpreter does its best to cope with this,
and MySQL gives it much more specific exceptions to work with.
Before switching to MySQL in another server, it is recommended to do it in your development environment first...
To switch your development environment to use MySQL see using MySQL in development.
There are 4 key ingredients to making JumpStart work with MySQL:
- Database driver
You already have a MySQL driver in the project if you followed using MySQL in development.
- Add the driver to the server:
- For WildFly 11: Install the MySQL driver as a module as explained in Data Source Configuration in AS 7.
- For Tomcat 7: Copy the MySQL driver to Tomcat's lib/ directory.
- For Glassfish 3: Copy the MySQL driver to Glassfish's glassfish/lib/ directory.
- Add the driver to the Eclipse client user library, which enables integration tests from Eclipse:
- For WildFly 11: In Eclipse, add the MySQL driver to your wildfly client user library, eg. wildfly-11.0.0-client-lib .
- For Tomcat 7: In Eclipse, add the MySQL driver to your tomcat client user library, eg. tomcat-7.0-client-lib .
- For Glassfish 3: In Eclipse, add the MySQL driver to your glassfish client user library, eg. glassfish-3.1.2.2-client-lib .
- Add the driver to the Ant script client lib path, which enables integration tests from Ant:
- For WildFly 11: In Eclipse, edit business/build.xml: add the MySQL driver to path classpath.wildlfy11.client.lib .
- For Tomcat 7: In Eclipse, edit business/build.xml: add the MySQL driver to path classpath.tomcat7.client.lib.
- For Glassfish 3: In Eclipse, edit business/build.xml: add the MySQL driver to path classpath.glassfish3.client.lib .
- Add the driver to the server:
- Data source definition
You already have this in your development environment if you followed using MySQL in development.- Add a data source definition to the server:
- For WildFly 11: When preparing as per WildFly 11.0.0, when you get to "Add the data source JumpStartDS" you should find the datasource is already there because you added MySQL as a module in the steps above. Now do something similar to "Make WildFly's H2 Database module available to all deployments".
- For Tomcat 7: When preparing as per Tomcat 7.0, when you get to "Note the data source" do this instead:
- Modify the 2 DataSource entries mentioned in "Note the data source" to match those in business/src/test/conf/openejb.xml.
- For Glassfish 3: When preparing as per Glassfish 3.1.2.2, when you get to "Add the data source jdbc/JumpStartDS" do this instead:
- In the Admin Console, choose Resources > JDBC > JDBC Connection Pools
- Add a connection pool for MySQL. If you don't know what values to choose, start with
Resource Type = javax.sql.ConnectionPoolDataSource, DatabaseDriverVendor = MySql, Introspect = no.
On the next page be sure to set DatabaseName, ServerName, User, Password, Url, and URL! - In the Admin Console, choose Resources > JDBC > JDBC Resources
- Add new (or modify existing) resource jdbc/JumpStartDS, setting it to use your MySQL connection pool. The name of this resource is crucial - it is referred to by name in JumpStart's persistence.xml as the jta-data-source.
- Add a data source definition to the server:
- persistence.xml
You already have a persistence.xml that is suitable for the development environment with MySQL if you followed using MySQL in development.
- Configure JumpStart's Ant scripts to include a suitable persistence.xml in the package (an EAR or WAR) that it creates:
- Edit the project's build.properties file, setting deployment.persistence.descriptor to the appropriate value for your server.
- For WildFly 11: Review wildfly-hibernate-mysql-persistence.xml.
- Hibernate 4 has new strategies for generating entity IDs. By default Hibernate disables them but WildFly 11 enables them!
You can disable them again by adding the following to business/src/main/resources/persistence-descriptor/wildfly-hibernate-mysql-persistence.xml:
<property name="hibernate.id.new_generator_mappings" value="false"/>
For more information see https://community.jboss.org/thread/170623 .
- Hibernate 4 has new strategies for generating entity IDs. By default Hibernate disables them but WildFly 11 enables them!
- Configure JumpStart's Ant scripts to include a suitable persistence.xml in the package (an EAR or WAR) that it creates:
- HibernatePersistenceExceptionInterpreter
This is a custom class responsible for interpreting vague exceptions like "constraint violation" into specific JumpStart exceptions.
- For HSQLDB, Derby, and MySQL, no change to this class is necessary.
- For other database types, you can modify this class, then test the modifications by running the integration tests.
Now build, deploy, and test JumpStart with MySQL:
- In Eclipse, drag build.xml to the Ant view and run its target clean-compile-test-package-deploytoserver .
- Restart the server.
- In Eclipse, run target clean-compile-test-package-deploytoserver-integrationtest .
OTHER DATABASE BRANDS
JumpStart has been tested with HSQLDB, H2, Derby, and MySQL.
If you wish to modify JumpStart to work with another database type, it is probably best to base your modifications on JumpStart's handling of MySQL. See MYSQL.
OTHER SERVERS
The following links show how to prepare other servers and how to build, deploy and test JumpStart on them:
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. wildfly 11.0, tomcat 7.0, glassfish 2.1) 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 WildFly.
- The package is a WAR file for Jetty and Tomcat,
in "collapsed EAR" format.