Tomcat

In this page are described the steps to follow to deploy a web-application based on the smartweb framework on Tomcat Server.

Environment Details:

Needed Libraries (MVN Repository)

  • postgresql.jar
  • jta-1.0.1B.jar

Tomcat setup


The first thing to do is to add a new system property when you run tomcat.
It can be done by adding an argument when lunching tomcat from shell

-Dsmartweb.factory.strategy=net.smartlab.web.config.TomcatConfigurationStrategy

This allows smartweb to use the appropriate configuration when running on tomcat server.

Add javax transaction library:

- Download javax transaction library jta-1.0.1B.jar and copy it to $TOMCAT/common/lib

DataSource setup


The following steps describe how to configure a jndi datasource if you are using PostgreSQL as database.

Configurations for other databases can be found at this link Tomcat JNDI Datasource HOW-TO

  1. Download PostgreSQL jdbc jar and copy it to $TOMCAT/common/lib
  2. Supposing that you want to configure a datasource accessible from any web-application deployed on tomcat you need to edit $TOMCAT/conf/context.xml adding the following code.
<Resource name="jdbc/DBname" auth="Container"
          type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
          url="jdbc:postgresql://127.0.0.1:5432/DBname"
        username="username" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>

The next step is to include a reference to this jdbc datasource in your application and so you have to edit the configuration file web.xml that can be found in the WEB-INF directory of your application ($TOMCAT/webapps/yourApp/WEB-INF)
You need to add the following code:

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

SmartWeb and Hibernate Configuration


The last step is to allow hibernate to access the datasource and so you need to edit smartweb.hcf.xml that can be found at ($TOMCAT/webapps/yourApp/WEB-INF/classes/META-INF).
The following code includes the basic property to include in your session factory configuration.
If you were using your application on JBoss and now you are editing your smartweb.hcf.xml be sure to remove any property referring to transaction like "transaction.factory_class" and "transaction.manager_lookup_class".

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="show_sql">true</property>
        <property name="use_outer_join">true</property>
        <property name="batch_size">10</property>
        <property name="connection.datasource">java:/comp/env/jdbc/DBname</property> 
        <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    </session-factory>
</hibernate-configuration>

Now start Tomcat and your application should work.
This procedure was tested on Tomcat 5.5.27.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.