tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Ludwig <>
Subject Re: Deploying mysql-connector-java-5.1.7-bin.jar in /WEB-INF/lib
Date Sun, 23 Nov 2008 15:58:30 GMT
IƱigo Mediavilla Saiz schrieb am 23.11.2008 um 11:08:52 (+0000):
> When I try to access to a Database through the connector it fails if I
> leave it inside WEB-INF\lib, but everything works if I copy the jar in
> the lib folder of the apache distribution.

Putting the driver in WEB-INF/lib only allows connections to be
established via java.sql.DriverManager, doing Class.forName(DRIVER).

> I'm using apache 6.0.18 and the exception I receive when I try to 
> access the db is:
> org.apache.tomcat.dbcp.dbcp.SQLNestedException:
> Cannot load JDBC driver class '' at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource( ...

You're trying to use the connection pool via javax.sql.DataSource and a
configured <Resource>. This fails, because the container doesn't have
the driver, only the web app has it.

> Is there any other way to let a web app access to a lib without having
> to copy the jar in apache\lib?

Yes: In Tomcat 6, to make the driver available for use in a connection
pool <Resource> without copying it to Tomcat\lib, edit the configuration
file Tomcat\conf\ and add the driver jar to the
"common.loader" property.


Note the syntax particularities:

* comma-separated
* file URIs (three slashes mean there is no host part)
* Windows drive letter as first path component

This has the same effect as copying the JAR into Tomcat/lib. In fact,
you can see that Tomcat/lib is part of "common.loader".

The Tomcat documentation says of the "Common" classloader: "Normally,
application classes should NOT be placed here." But for a JNDI
datasource, the "Common" classloader is needed.

If instead you wanted to make the driver available to all web apps
without using JNDI and the connection pool (which generally is not a
recommended technique for database drivers), you'd add it to the
"shared.loader" property in the same file. That way, you wouldn't have
to copy it into all WEB-INF/lib directories. The server won't see what
you add here.

For completeness, there is also the "server.loader", where you may add
classes only the server is supposed to see.

* server.loader -> for the container, Tomcat
* shared.loader -> for all web apps
* common.loader -> for both the container and all web apps

Tomcat's classloading mechanism has changed slightly between 5 and 6.
In Tomcat 5, there were Tomcat/{server,shared,common}/{lib,classes}.
In Tomcat 6, there is only a unified Tomcat/lib directory.

Finer granularity of class loading seems only to be possible via the
file "conf/". The Tomcat 6 documentation doesn't
reveal this yet, though.

Michael Ludwig

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message