Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Externally hosted Tomcat: How to use DB-Driver if not in %CATALINA-HOME%/lib ???

 
Tom Dallas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody!

I got a question: I run a webapp on a shared Tomcat-server with 15 other instances, and the admin refuses to put the mysql-connector in the main tomcat/lib directory. Everywhere on the web you only can read: put it there or you'll have problems. How can I use the driver from within the webapp? Just putting it in the WEB-INF/lib doesn't work : Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for datasource"

Anybody experiences with this? Please don't tell me I should put it in the tomcats' main lib: the admin says there must be a way to do this as one other client found a solution.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put my connector in WEB-INF/lib and it works fine

/work/webapp/WEB-INF/lib/mysql-connector-java-5.0.5.jar

Check how your application deploys or if it is actually including the connector. Maybe your war is not including it. You might want to setup a local tomcat install. Deploy there and check if it works.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using container-managed pooling? If so, the container must have access to the driver outside the class loader of specific apps, and that's why it needs to be in the "central" lib folder.

 
Tom Dallas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ... of course, the container-managed pooling won't work! I managed to use the driver the usual way when its deployed within the application, I just thought I could use the container-managed pooling :-/

Thanks!
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Dallas wrote:Hello Everybody!

I got a question: I run a webapp on a shared Tomcat-server with 15 other instances, and the admin refuses to put the mysql-connector in the main tomcat/lib directory. Everywhere on the web you only can read: put it there or you'll have problems. How can I use the driver from within the webapp? Just putting it in the WEB-INF/lib doesn't work : Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for datasource"

Anybody experiences with this? Please don't tell me I should put it in the tomcats' main lib: the admin says there must be a way to do this as one other client found a solution.


I've got a nasty feeling that your sources are all kitchen-table webapps that don't do pooling. Which is often problem enough right there. What their further issues were, I don't know and hope to never need to find out.

Not only do I always define my drivers in the Tomcat lib directory, I often softlink them in. For example, the OS-installed jdbc drivers in Red Hat Linux these days end up under the /usr/share/java tree. Rather than copy them, I just put softlinks in CATALINA_HOME/lib.
 
Tom Dallas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I'd also do this, but as I have written this instance of Tomcat runs in shared mode and the admin doesn't want to include (also softlinked) DB-drivers ... which might make sense due to probable version-conflicts. Perhaps another customer really wants to use some Version 3 Connector while I want the latest 5.x.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Dallas wrote:Yeah I'd also do this, but as I have written this instance of Tomcat runs in shared mode and the admin doesn't want to include (also softlinked) DB-drivers ... which might make sense due to probable version-conflicts. Perhaps another customer really wants to use some Version 3 Connector while I want the latest 5.x.


That's indicative of a bigger problem. The whole idea of a pool is that it's a resource that can be externally tuned and balanced by the sysadmin at the system level, not defined within a single app where you'd have to either code explicit logic to control it or at least rebuild the WAR. At the Enterprise level, "Sharing is Caring".

Since (unlike Microsoft) Java code is "supposed" to be backwards compatible, there's no (theoretical) reason what V3 code can't run under a V5 driver. Of course, theory and practice unfortunately don't always coincide.

It's not like Tomcat is some sort of enormous monster eating so much space that you can't keep a spare copy on disk, however. With the V5 connector in it. Especially if you're running multiple instances anyway.
 
Tom Dallas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
:-)

I told the admin to just add the connector, but other clients of his already might have coded solutions with their own connectors in it. He could have done it and told every other client: please take out your connectors so you don't have a duplicate jar on the classpath - but I guess he didn't want to do that.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Dallas wrote::-)

I told the admin to just add the connector, but other clients of his already might have coded solutions with their own connectors in it. He could have done it and told every other client: please take out your connectors so you don't have a duplicate jar on the classpath - but I guess he didn't want to do that.


Well, if they actually coded connectors in their apps, they shouldn't be a problem. When you use a database connection pool, you just use JDNI to locate the pool's DataSource object and get Connections from them. Connection is an interface, so unless they break transparency and cast the connection to a specific class, that's not likely to matter.

On the other hand, some people do break transparency. For example, there are additional features that the Oracle and PostgreSQL drivers offer (mostly DB-specific datatypes). So it does happen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic