0

I have a number of JDBC Driver jar files in my webapp's WEB-INF/lib - e.g. oracle and SQL-Server. In Tomcat7, if the webapp only uses oracle, the SQL-Server driver doesn't get registered, but in Tomcat6 it does (I can see this from my contextDestroyed() in a ServletContextListener, which de-registers Drivers loaded by this classloader).

Is Tomcat6 somehow pre-loading classes from jars in WEB-INF/lib? If so, can this be disabled?

(I know these jars would be better in the shared lib, but this is another issue...)

Mick Francis
  • 139
  • 6

1 Answers1

1

Never ever put drivers in the webapp class path. Put it always into the server's classpath.

Declare a DataSource then in your context.xml and then free the resources with this.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • It's not really answering the question, but I totally agree with your statement. +1 – Maurice Perry Dec 05 '13 at 12:21
  • Yes, but as I said, this is a separate issue. I am stuck with having to have the drivers where they are, as different webapps may use different driver versions, etc. Just wondered about the pre-loading thing... – Mick Francis Dec 05 '13 at 12:42
  • You cannot use different version of the same class file. This would probably require OSGi. – Michael-O Dec 05 '13 at 15:26
  • 1
    Yes you can, because they are in different ClassLoaders - each webapp has its own ClassLoader. – Mick Francis Dec 05 '13 at 16:15
  • @Michael-O why are drivers in `WEB-INF/lib` an issue? I suspect it matters when the server creates the connection pool, but if the app manages it (via Spring, etc), `WEB-INF/lib` is where the libraries _should_ reside? – raffian Dec 05 '13 at 18:58
  • @raffian,the thing is that if you load the same driver twice you might get into `DriverManager` problems. It was not designed for multi-classloaders. It assumes that the driver is always loaded once per VM. Read [this](http://stackoverflow.com/a/7198049/696632) answer please. – Michael-O Dec 05 '13 at 19:41