Apache Derby can be integrated with Google Web Toolkit. It requires, however, a few tricks. As it wasn’t all that straight forward, and included some time-consuming hunting-around on the Internet, I thought I would publish the troubles ( java.lang.ClassNotFoundException, java.lang.NoClassDefFoundError: java.io.FileOutputStream, and java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.(Ljava/lang/Object;)V)) and answers all in once place. I hope it helps!
I am constructing a web-based application using Google Web Toolkit (for use on my workstation, and not hosted by Google). As I am storing and manipulating large amounts of data I decided that a relational database is the best technology for storing data. As technology I picked Apache Derby (embedded).
The Software Versions
The specific software versions I am using are:
- Development Environment: Eclipse Helios (3.6) Service Release 2,
- Apache Derby: 10.8.1.2,
- Google Web Toolkit 2.3.0
You will already encounter the explained issues if you are creating a new Google Web Application project, generate the “GWT sample code”, and modify the class GreetingServiceImpl.java to do nothing more than opening a database connection to an embedded Derby database.
If you want to learn about Apache Derby and GWT, this article is a good place to start, even though it is a little older: “Build an Ajax application using Google Web Toolkit, Apache Derby, and Eclipse, Part 3: Communication”.
Issue #1: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
The application will throw this exception when a database connection is opened.
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.Class.forName0(Native Method)
This is probably one of the more obvious exceptions. You need to add the jar file containing the embedded database code as well as JDBC driver to the application’s compile- and run-time classpaths.
Two things could have gone wrong here:
- You may have forgotten to add the file derby.jar to the build path of the project.
- In addition, though, you need to add the file derby.jar to the war/WEB-INF/lib/ directory.
Issue #2: java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google App Engine developer’s guide for more details.
This application throws this application when the application tries to open a connection.
Caused by: java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google App Engine developer’s guide for more details.
The GWT application runs in a sandbox, and simply does not allow particular accesses, such as using java.io.FileoutputStream into the local file-system. For a more complete picture please refer to “Google App Engine – The Java Servlet Engine: The Sandbox”.
The fix is simple as well. Just disable the Google App Engine support for your application. Do this by right-clicking your Google Web Project, then select Properties > Google > App Engine.
This one is one of the more obvious ones. Anyway, if you run into it you probably have only added the jar file, containing the derby embedded JDBC driver, to your Eclipse build-path only.
Issue #3: Exception in thread “main” java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.(Ljava/lang/Object;)V
Finally, I received the exception above. This already occurs at the startup of the Google Application Engine.
Exception in thread “main” java.lang.NoSuchMethodError: org.mortbay.thread.Timeout.(Ljava/lang/Object;)V
About the reasons I am not entirely sure. I did not take the time to investigate it. But it seems that there is an incompatibility between the Jetty Engine and a class required by the Google Web Toolkit. Thanks to Kim Hansen’s comment on Erik Scholtz’s blog entry “org.mortbay.thread.Timeout. exception on new GWT webapplication with instantiations gwt designer or windowbuilder pro”, I was able to save a lot of time.
Also here, the fix is easy. Open your project’s build path and go to the “Order and Export” tab: Right-click project > Properties > Java Build Path > Order and Export tab.
Next move the GWT SDK library, at least, above the Google App Engine libraries. Then confirm it by selecting OK. It will make it work.
Finally, you will be able to start your Google Web Toolkit application, using an embedded Apache Derby database.