aspose file tools*
The moose likes Tomcat and the fly likes obatining JNDI connection in load-on-startup or context listener? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "obatining JNDI connection in load-on-startup or context listener?" Watch "obatining JNDI connection in load-on-startup or context listener?" New topic
Author

obatining JNDI connection in load-on-startup or context listener?

andrew low
Greenhorn

Joined: Mar 22, 2005
Posts: 18
I want to add some data into the application context of my web application.

I have tried to bind a listener to the application context, and I have tried to have a servlet with an load-on-startup parameter. Both of these fail as the attempt to find the context can't find the context. If I use a servlet to run the various calls once the application has finished starting up everything is cool. Is this because the <resource-ref> is last in web.xml and means that I simply can't do this? And does anyone have an alternative they could suggest?

Many thanks

Andrew
[ March 23, 2005: Message edited by: andrew low ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
It sounds like this is more of a deployment descriptor issue than a tomcat issue. It would help if you posted any error message(s) and your web.xml.
andrew low
Greenhorn

Joined: Mar 22, 2005
Posts: 18
The error is

Cannot create JDBC driver of class '' for connect URL 'null'

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:743)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
at com.xxxx.phonelist.country.CountryListDAO.<init>(CountryListDAO.java:22)
at com.xxxx.phonelist.init.StartUp.init(StartUp.java:24)
at javax.servlet.GenericServlet.init(GenericServlet.java:256


and the web.xml is as follows, but I can use this JNDI connection once the application is up and running.

Thanks

Andrew


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>DefaultWebModule</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>startup</servlet-name>
<servlet-class>com.xxxx.phonelist.init.StartUp</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet>
<servlet-name>debugjsp</servlet-name>
<description>Added by JBuilder to compile JSPs with debug info</description>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>classdebuginfo</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>startup</servlet-name>
<url-pattern>/servlet/startup</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>debugjsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>5</session-timeout>
</session-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<resource-ref>
<description>Oracle Datasource</description>
<res-ref-name>jdbc/intranetDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
[ March 23, 2005: Message edited by: andrew low ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
It looks like the location of the JDBC driver configured for your JNDI resource is unknown from your application


I would make sure the spelling of the driverClassName is correctly pointing to the location of your JDBC driver i.e.

and the jar file is in your classpath.

But, it is strange you, that you are able to access the resource after the startup completes.
sudeep philip
Greenhorn

Joined: Nov 28, 2002
Posts: 5
the easiest way is to copy the jar to %tomcat_home%/common/lib directory. During the startup all the jar in that directory is in classpath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: obatining JNDI connection in load-on-startup or context listener?