Tuesday, June 15, 2010

ehcache relies on slf4j

I couldn't get my unit tests to run from my Ant task after switching to ehcache for Hibernate. Every test would fail with the following error:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.ehcache.hibernate.EhCacheProvider
I followed the instructions in this blog entry to pretty print the classpath and confirm that ehcache.jar was indeed on the Junit test classpath. The application runs fine inside the app server, so what gives?

I solved the mystery by modifying my test so that it only ran one line of code:
System.out.println(Class.forName("net.sf.ehcache.hibernate.EhCacheProvider").newInstance());
This gave me a more useful error message:
java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.LoggerFactory
Aha! I didn't have jboss-home/common/lib/sfl4j-api.jar on my classpath. I added it and one other slf4j jar to my classpath and my problem was solved.

There goes two hours due to a misleading error message.

Thursday, June 10, 2010

XPlanner+ installation

How to install a private instance of XPlanner+ on JBoss 5.1.0.  These instructions assume that you have already downloaded and unzipped JBoss AS 5.1.0.
  • Download the WAR file from the XPlanner+ web site.
  • Expand the WAR file into a new folder within <jboss_home>/server/default/deploy, and then rename the folder xplanner-plus.war
  • Delete <jboss_home>/server/default/deploy/xplanner-plus.war/WEB-INF/lib/xml-apis-1.0.b2.jar because this causes a deployment failure with the following error:
    java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl  cannot be cast to javax.xml.parsers.DocumentBuilderFactory
  • Start JBoss using <jboss_home>/bin/run -b 0.0.0.0 so that the application is available from other machines. The default behavior for JBoss is to only serve pages to localhost.
The current version of XPlanner+ creats an in-memory HSQLDB instance that is fast and requires no configuration.  It also persists the data on a clean server shutdown by updating <jboss_home>/bin/hsqldb/xplanner.script.  If the server is abruptly shutdown then it reconstructs the data from <jboss_home>/bin/hsqldb/xplanner.log.  It's a simple and effective scheme and it makes moving the data to another relational database relatively easy because xplanner.script contains both the DML and the DDL to recreate the entire database. One disadvantage is that you cannot connect to the database from an external JDBC tool.