OpenShift Development


December 5, 2013 Maithilish

12.5. OpenShift Development

Without any changes to the code, we are able to deploy Fins to OpenShift. But, you may require a local setup to develop your app before moving it to OpenShift, and this section shows how to develop GWT applications with Tomcat.
Setup Tomcat

Extract Tomcat archive to some location on your system and we refer this folder as CATALINA_HOME.

Officially suggested method to run GWT on external server is to copy static, image files and gwt dir to tomcat/webapps and on any changes in server side classes (like rcp etc.,) or static files, we need to copy them again to tomcat.
Instead, we may point tomcat to project’s war directory so that tomcat runs the app directly from Eclipse workspace and on any changes, reloads the application.
To begin with, point Tomcat to war dir of GWT project. To do this, add <appname>.xml to $CATALINA_HOME/conf/Catalina/localhost. Change docBase attribute to absolute path of the project war directory.
$CATALINA_HOME/conf/Catalina/localhost/fins.xml

<Context path="/fins" docBase="/home/m/workspace/fins/war" reloadable="true">
</Context>

  • docBase attribute points to project’s war dir in eclipse and with this tomcat is able to run the web app directly from eclipse workspace without copying files to tomcat/webapps dir.
  • reloadable attribute ensures that tomcat reloads the app whenever files are modified in workspace.
There are two options to define database connection. Set Connection URL, user name and password directly in jdoconfig.xml
src/META-INF/jdoconfig.xml

....
<persistence-manager-factory name="datastore">
    <property name="javax.jdo.PersistenceManagerFactoryClass"
              value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
    <property name="javax.jdo.option.ConnectionDriverName" 
              value="org.hsqldb.jdbcDriver" />
    <property name="javax.jdo.option.ConnectionURL" 
              value="jdbc:hsqldb:hsql://localhost/finsdb" />
    <property name="javax.jdo.option.ConnectionUserName" value="sa" />
    <property name="javax.jdo.option.ConnectionPassword" value="" />
....

 
Other option is to define JNDI resource within Context element in context file fins.xml and add it as resource-ref in web.xml.
$CATALINA_HOME/conf/Catalina/localhost/fins.xml

<Context path="/fins" docBase="/home/m/workspace/fins/war" reloadable="true">
      <Resource name="jdbc/datastore" 
          url="jdbc:hsqldb:hsql://localhost/finsdb"
          driverClassName="org.hsqldb.jdbcDriver"
          username="sa" password="" 
          auth="Container" type="javax.sql.DataSource"
          maxActive="20" maxIdle="5" maxWait="10000" />
</Context>

war/WEB-INF/web.xml

....
<resource-ref>
  <description>DataSource</description>
  <res-ref-name>jdbc/datastore</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>
....

src/META-INF/jdoconfig.xml

....
<persistence-manager-factory name="datastore">
    <property name="javax.jdo.PersistenceManagerFactoryClass"
              value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
    <property name="javax.jdo.option.ConnectionFactoryName"
              value="java:comp/env/jdbc/datastore" />
....

Enhance the classes with DataNucleus Enhancer and start HSQLDB database. Then start tomcat with $CATALINA_HOME/bin/startup.sh. Fins should be accessible at http://localhost:8080/fins. Make some changes to application in Eclipse and check whether tomcat reloads the app (view $CATALINA_HOME/logs/catalina.out for reload logs).
GWT Development Mode

To run the app in GWT Dev mode, go to “Run As” option in project context menu and select “Web Application (Running on external server)”. Enter external server root as fins and give html page as Fins.html. This will run the GWT app in development mode without running embedded Jetty server.

But, app URL still points to http://localhost:8888/fins/Fins.html. To change this, modify Run configuration. Go to run configurations and select Fin.html (external). Change Browsers URL field in GWT tab to http://localhost:8080/Fins/Fins.html
Run Configuration
Figure 12.4. Run Configuration


Run the app again and access the app at http://localhost:8080/fins/Fins.html?gwt.codesvr=127.0.0.1:9997. Now, you will be able to use GWT Dev mode to run and debug GWT app.
Forward Pointers

OpenShift User GuideUser Guide

OpenShift System ArchitectureOpenShift Architecture