The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tomcat, need Resource element in Context

Discussion in 'General Discussion' started by jerrek71, Jan 27, 2009.

  1. jerrek71

    jerrek71 Active Member

    Joined:
    Jul 27, 2006
    Messages:
    42
    Likes Received:
    1
    Trophy Points:
    6
    Hi all,
    I have a couple of JSP webapps, both of which use JNDI named Datasources which are used through the DBCP Connection pooling features of Tomcat.

    I can get these working if I manually add a Resource element to the server.xml that CPanel generates, however of course as soon as I add 'servlets' to a new domain, my changes are overwritten and the Resource section of my Context is gone.

    I've tried putting a META-INF/context.xml in my webapp itself, but because the Context is specified in server.xml by the cpanel generator, any context.xml I put in my own webapp seems to be ignored. I don't think we can do away with the Context in server.xml either because otherwise TC won't know to look into user's directories for the webapps.

    So, is there any way of being able to specify JDNI named resources / DataSources which would not be overwritten when I add servlet capability to someone elses domain?

    My Context looks something like this;

    Code:
    <Host name="removed-for-safety.com" appBase="/home/username/public_html">
              <Alias>www.removed-for-safety.com</Alias> 
              <Context path="" reloadable="true" docBase="/home/username/public_html" debug="1">
              <Resource   name="jdbc/MyDS"                                      
              auth="Container"
              type="javax.sql.DataSource"
              factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
              driverClassName="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost/username_dbname" 
              validationQuery="select 1"
              username="username_dbname" 
              password="uhuh"
              maxActive="20" maxIdle="0" maxWait="60000"
              removeAbandoned="true"
                              logAbandoned="true" removeAbandonedTimeout="300">
                                              </Resource>
                                              </Context>
              <Context path="/manager" debug="0" privileged="true"
                  docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
              </Context>
           </Host>
    So you can see the added Resource section.

    This becomes even more important if you want to use a Spring and Hibernate solution as all the database access is 'virtualised' away so you can't see it happening... You can't just do standard JDBC calls in your code any more, you must provide a DataSource they can connect to.

    Hope someone can shed some light for me.

    Cheers,
    Steve
     
Loading...

Share This Page