tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Hart <kevin.h...@stanford.edu>
Subject Re: NamingException: Cannot create resource instance
Date Sat, 09 Sep 2006 21:59:32 GMT
David,

Thanks for your reply.  It turns out the solution had two parts: 1) there is
a problem with the FC5 distro that requires a work-around; and 2) apparently
there is only *one* successful way to configure the JNDI resource even
after applying the work-around.

THE FC5 DISTRO PROBLEM.  Credit goes to Richard Bullington-McGuire for
posting this nugget on his PKR Internet site (I think he was looking at a
different problem that had the same root cause):

Investigation revealed that the JPackage-derived Fedora Core 5 tomcat5 RPM
was looking for the naming factory
org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory, but that class is not
included in the set of jars in ${tomcat.home}/common/lib. As shipped from
the vendor, Tomcat 5.5 includes a jar called naming-factory-dbcp.jar, but
to conform with the JPackage policy of removing binary jars and having
upgradeable components, the JPackage-style build used the stock
commons-dbcp.jar instead.  To work around this on Fedora Core 5, you can
either set an attribute in the context.xml file,
factory="org.apache.commons.dbcp.BasicDataSourceFactory", or you can set a
Java system property in /etc/tomcat5/tomcat5.conf and restart Tomcat.

Bottom line: If you're using the FC5 distro, you need to include a
factory="org.apache.commons.dbcp.BasicDataSourceFactory" attribute in your
JNDI resource definition.

THE ONLY CONFIGURATION THAT WORKED.  Even after applying the above fix, the
only configuration that worked was to define the JNDI resource in a web
application-specific way (put it in the META-INF/context.xml file).  I
tried defining it in a <DefaultContext> element within the server.xml
<host> element.  That didn't work.  And I tried defining it as a global
naming resource in the server.xml file with a resource-link in
META-INF/context.xml.  That didn't work either.  But it does work to define
the resource in META-INF/context.xml with a resource-ref in
WEB-INF/web.xml.

I hope this helps other FC5 folks who are trying to use Tomcat 5.5.x.

--Kevin

Quoting David Smith <dns4@cornell.edu>:

> The method of defining JNDI resources in tomcat changed from 5.0 to
> 5.5.  The book appears to be describing the method for 5.5.  See
>
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> for details related to tomcat 5.5.
>
> The java code used in jsps and servlets to access the data source is
> still the same.  That part can come from the book.
>
> --David
>
> Kevin Hart wrote:
> > The attachments in my previous message got mangled.  Sorry, I'm a
> newbie.
> > Here is the relevant portion of the server.xml file (the formatting in
> this
> > will probably get mangled too):
> >
> > ..
> > <DefaultContext>
> > <Resource name="jdbc/WroxTC5" auth="Container"
> type="javax.sql.DataSource"/>
> > <ResourceParams name="jdbc/WroxTC5">
> >
>
<parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
> >
>
<parameter><name>url</name><value>jdbc:mysql://localhost/wroxtomcat</value></parameter>
> > <parameter><name>username</name><value>*****</value></parameter>
> > <parameter><name>password</name><value>*****</value></parameter>
> > <parameter><name>maxActive</name><value>20</value></parameter>
> > <parameter><name>maxIdle</name><value>30000</value></parameter>
> > <parameter><name>maxWait</name><value>100</value></parameter>
> >
>
<parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>
> > </ResourceParams>
> > </DefaultContext>
> >
> >       </Host>
> >     </Engine>
> >   </Service>
> > </Server>
> >
> > And here is the relevant portion of the web.xml file:
> >
> > ..
> > <resource-ref>
> >    <res-ref-name>jdbc/WroxTC5</res-ref-name>
> >    <res-type>javax.sql.DataSource</res-type>
> >    <res-auth>Container</res-auth>
> > </resource-ref>
> > </web-app>
> >
> > The code in the jsp that generates the exception is line 14 of the
> following
> > snippet:
> >
> > ..
> > 11: <%
> > 12: InitialContext initCtx = new InitialContext();
> > 13: if( initCtx != null ) {
> > 14:    DataSource ds = (DataSource)
> > initCtx.lookup("java:comp/env/jdbc/WroxTC5");
> > 15:    Connection conn = ds.getConnection();
> > 16:    Statement stmt = conn.createStatement();
> > 17:    ResultSet rset = stmt.executeQuery("select * from employee;");
> > ..
> >
> > As you can see, I'm just trying to get an example working.
> >
> > Thanks again for any help,
> > Kevin
> >
> > Quoting Kevin Hart <kevin.hart@stanford.edu>:
> >
> >
> >> Hello,
> >>
> >> I'm trying to get a jsp to access a mysql database.  I'm using the
> >> "preferred" JNDI resources approach with Tomcat, but I keep getting
> the
> >> NamingException: Cannot create resource instance error.  I know others
> >> have posted with this error.  I've read some of those posts, but
> >> the solutions don't seem to fix the problem in my case.
> >>
> >> I'm using FC5, MySql 5.0.22 and Apache Tomcat 5.5.15.  I attach the
> >> following files:
> >>
> >> exception.report is a copy of the html page showing the error.
> >>
> >> common.lib.contents is the output of a script session to show the
> >> contents of my /usr/share/tomcat5/common/lib directory.  I have at
> least
> >> the
> >> following in there: mysql-connector-java-5.0.3-bin.jar,
> commons-pool.jar,
> >> common-collections.jar, naming-factory.jar and naming-resources.jar.
> >>
> >> server.xml is my /usr/share/tomcat5/conf/server.xml file.  I have a
> >> <Resource> tag inside a <DefaultContext> tag inside the <host>
element
> >> (see the end of the file).
> >>
> >> web.xml is from the jsp-examples/WEB-INF directory.  (I'm just tacking
> >> my jdbctest.jsp onto the existing jsp-examples webapp.)  The
> >> <resource-ref> tag is at the end of that file.
> >>
> >> Having no experience with Tomcat, I'm basically following instructions
> >> from Wrox's book "Professional Apache Tomcat 5."  I must be misreading
> >> it.
> >>
> >> Thanks in advance,
> >> Kevin
> >>
> >>
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
>
> --
> David Smith
> Network Operations Supervisor
> Department of Entomology
> Cornell University
> 2132 Comstock Hall
> Ithaca, NY 14853
> Phone: (607) 255-9571
> Fax: (607) 255-0940
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message