Fernando
Fernando

Reputation: 4629

javax.naming.NamingException: Could not create resource factory instance

First of all i'm not a Java developer. I just need to get a simple jsp examples that connects to a postgres database and retrieve some information.

I got it running on a local env, but when i try to run on production server ( Apache Tomcat 6.0.29 ), it just doesn't work. Page displays the following exception:

org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/postgres"
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I noticed that when i reload the application, catalina.out shows the following problem:

Aug 23, 2011 2:21:07 PM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

At WEB-INF/lib i have the following files:

# ls -lh
total 1.3M
-rwxr-xr-x 1 tomcat tomcat  17K Aug 23 14:15 jstl.jar
-rwxr-xr-x 1 tomcat tomcat 160K Mar  5  2007 naming-factory-dbcp.jar
-rwxr-xr-x 1 tomcat tomcat 528K Aug 23 14:18 postgresql-9.0-801.jdbc4.jar
-rwxr-xr-x 1 tomcat tomcat 313K Aug 23 14:16 standard.jar
-rwxr-xr-x 1 tomcat tomcat 248K Aug 22 22:18 tomcat-dbcp.jar

I tried googling about this but all solutions mention naming-factory-dbcp.jar that is already there. Any ideas of what i should do?

Thanks!

EDIT

Here is my tomcat lib:

-rw-r--r-- 1 tomcat nobody  11K Jun  8  2009 lib/annotations-api.jar
-rw-r--r-- 1 tomcat nobody  49K Jun  8  2009 lib/catalina-ant.jar
-rw-r--r-- 1 tomcat nobody 121K Jun  8  2009 lib/catalina-ha.jar
-rw-r--r-- 1 tomcat nobody 1.1M Jun  8  2009 lib/catalina.jar
-rw-r--r-- 1 tomcat nobody 225K Jun  8  2009 lib/catalina-tribes.jar
-rw-r--r-- 1 tomcat nobody  28K Jun  8  2009 lib/el-api.jar
-rw-r--r-- 1 tomcat nobody 101K Jun  8  2009 lib/jasper-el.jar
-rw-r--r-- 1 tomcat nobody 501K Jun  8  2009 lib/jasper.jar
-rw-r--r-- 1 tomcat nobody 1.4M Jun  8  2009 lib/jasper-jdt.jar
-rw-r--r-- 1 tomcat nobody  75K Jun  8  2009 lib/jsp-api.jar
-rw-r--r-- 1 tomcat nobody  86K Jun  8  2009 lib/servlet-api.jar
-rw-r--r-- 1 tomcat nobody 732K Jun  8  2009 lib/tomcat-coyote.jar
-rw-r--r-- 1 tomcat nobody 193K Jun  8  2009 lib/tomcat-dbcp.jar
-rw-r--r-- 1 tomcat nobody  65K Jun  8  2009 lib/tomcat-i18n-es.jar
-rw-r--r-- 1 tomcat nobody  43K Jun  8  2009 lib/tomcat-i18n-fr.jar
-rw-r--r-- 1 tomcat nobody  48K Jun  8  2009 lib/tomcat-i18n-ja.jar

Upvotes: 3

Views: 23781

Answers (1)

home
home

Reputation: 12538

dbcp classes should already be available in tomcat/lib. There is no need to include then in your WAR file - it may lead to class loader irritations if you use the wrong version. Try to remove the ...dbcp.jar files from your WEB-INF/lib directory, put the postgres...jar to tomcat/lib and restart Tomcat.

Upvotes: 2

Related Questions