OpenTrader: a transactional, web application with Google Web Toolkit, OpenJPA/Slice on Tomcat
OpenTrader is a sample web application to demonstrate integration and interaction of Google Web Toolkit, OpenJPA and Tomcat Servlet Container.
Follow the steps to view OpenTrader source code, build the application, deploy it in your favorite application container and run it in your favorite browser.
1. Get the source code
OpenTrader source code is available as one of the OpenJPA examples. Checkout the source files in a directory.
$ svn checkout https://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/opentrader
The source tree comes with
- Ant build script:
build.xml
andbuild.properties
- Java source code for OpenTrader application under
src/main/java
- GWT module descriptor :
OpenTrader.gwt.xml
undersrc/main/java/org/apache/openjpa/trader
- Persistence descriptor :
persistence.xml
undersrc/main/resources/META-INF
- web descriptor :
web.xml
undersrc/main/resources/WEB-INF
- cascading style sheet :
OpenTrader.css
undersrc/main/resources/css
2. Build
To build OpenTrader you will require following other libraries.
- Google Web Toolkit: We have built it with GWT version 2.0.4 which can be downloaded from here.
- cobogw widget library: Provides rounded panel not using them seems to be too un-cool. Download version 1.3.1 from here.
- and, of course, OpenJPA libraries: OpenJPA now comes with all its dependencies neatly packaged in a single jar including the JPA API. Download from this site.
2.1 Configure build environment
Edit build.properties
to point to the dependent libraries you have downloaded. The file contains the instructions as comments.
2.2 Run Ant
{{ $ ant compile}}
will compile the source code, then compile it for GWT then compile it for OpenJPA. Compiling for GWT will take ages. Even though it only compiles for a single browser (FireFox).
This is controlled by the following directives in the module descriptor OpenTrader.gwt.xml
<set-property name="user.agent" value="gecko1_8"/>
3. Run
You can run either in hosted mode - an environment provided by GWT to run within a Jetty container - or in a proper servlet container such as Tomcat, Geronimo or GlassFish or even heavy-duty ones such as WebSphere or Weblogic. In either case, you have to configure the persistence.xml
found under src/main/resources/META-INF
. This descriptor specifies the database used by OpenTrader.
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/> <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost/exchange"/> <property name="openjpa.ConnectionUserName" value="whoami"/> <property name="openjpa.ConnectionPassword" value="secret"/>
Also edit the jdbc.driver
in build.properties
for the driver/database you have selected.
Now, for hosted mode, simply fire Ant as
{{ $ ant devmode}}
This should again take a very long time and pop open a horrible looking Swing console titled GWT Development Mode. Go to Development Mode tab and click Launch Default Browser. On my FireFox browser, that opens up the page http://127.0.0.1:8888/OpenTrader.html?gwt.codesvr=127.0.0.1:9997
. If all goes well, at this point your browser will prompt you with a welcome dialog box
Once you have entered OpenTrader, the browser application looks like