First let me say that this issue could have been completely avoided by using Sun's Application Server. For reasons beyond my control, I had to deploy an application written with Java Studio Creator 2 to Tomcat on Windows. I hope this information saves someone else some time..

Here are the product instructions: Sun Java Studio Creator 2 Update 1 – Online Help Deployment Example: Tomcat

This application uses a database which requires a datasource to be defined for the application server, and a fererence to the datasource in the applications web.xml file (Creator puts this there automatically). I have been successfully deploying this application onto linux and Solaris on both Sun Application Server and Tomcat without any major problems. In fact after simply creating a Tomcat JNDI datasource, it worked perfectly. On Tomcat Linux (Ubuntu 6.06 and Tomcat 5.5.17), all I had to do to create a datasource was add the following to the <tomcatroot>/conf/context.xml:
<Resource name="jdbc/hrlite" auth="Container"

    type="javax.sql.DataSource" username="hradmin" password="hradmin"

    driverClassName="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/hrlite"

    maxActive="8" maxIdle="4"/>


The trouble came when trying to deploy to a Windows Tomcat 5.5 server. The above technique for creating a datasource did not work for me. Also, JSF will not run on the Windows flavor of Tomcat without adding a listener to the web.xml file in your application, so the application would not even start. This is manifested by a Null Pointer Exception on FacesServlet.init when accessing the application . This was resolved after adding the following to the application web.xml file:

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>


Once the faces listener was added to my application's web.xml file, the creator came up, but when I went to a page in the application which used a datasource, I recieved an error from the RowSetReader. The datasource was clearly not being found.

So I attempted to add the database connection pool datasource as described in the Tomcat docs. The Apache Jakarta Tomcat 5 Servlet/JSP Container

I tried many variations and could not get past this issue. I did find many other people with similar problems and a lot of misinformation. But untimately, I resolved my issue by removing Tomcat 5.5.20 and installing Tomcat 5.0.28 since the docs for Tomcat 5.5 datasource appear to be outdated, and I may have been experiencing a bug. In any event, here is the final solution which is now working for me for creating a datasource in Tomcat 5.0 on Windows.

Add the datasource to the <tomcathome>\conf\server.xml

I added the following near the end of the file, right before the closing Host tag (</Host>)

<Context path="/hrlite" docBase="hrlite"
        debug="5" reloadable="true" crossContext="true">

  <Logger className="org.apache.catalina.logger.FileLogger"
             prefix="localhost_DBTest_log." suffix=".txt"
             timestamp="true"/>

  <Resource name="jdbc/hrlite"
               auth="Container"
               type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/hrlite">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
    <parameter>
      <name>maxActive</name>
      <value>100</value>
    </parameter>

    <!-- Maximum number of idle dB connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->
    <parameter>
      <name>maxIdle</name>
      <value>30</value>
    </parameter>

    <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value>hradmin</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>hradmin</value>
    </parameter>

    <!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next
         if you want to use this driver - we recommend using Connector/J though
     -->
    <parameter>
       <name>driverClassName</name>
       <value>org.gjt.mm.mysql.Driver</value>
    </parameter>

    
    <!-- Class name for the official MySQL Connector/J driver 
    <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
    </parameter>
     -->    


    <!-- The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
         connection.  mysqld by default closes idle connections after 8 hours.
         -->
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost/hrlite?autoReconnect=true</value>
    </parameter>
  </ResourceParams>
</Context>



Here are a few links which I found along the journey.


Tags: ,
Comments:

Post a Comment:
Comments are closed for this entry.

This blog copyright 2009 by harcey