Where should the JDBC driver JAR files reside on a Tomcat deployment with a datasource?

纵饮孤独 提交于 2019-11-28 12:22:05

That depends on who's managing the datasource.

If you're manually constructing and managing the datasource in your own webapp like so new SomeDataSource(), etc, then the JDBC driver JAR file can be placed in webapp's /WEB-INF/lib. But if appserver happen to provide the very same JDBC driver JAR file in its own /lib already, then you could also just make use of it.

However, if you're instructing appserver to manage the datasource all by itself and you're merely making use of it in your webapp via @Resource, etc, then the JDBC driver JAR file has to be placed in appserver's own /lib, for the very simple reason because the data source is prepared on appserver's startup completely independently from any (to be) deployed web applications. This data source is in turn shareable among all webapps. It would technically just not work if the JDBC driver JAR file is in one of the yet-to-be-deployed webapps.

Gyanendra Dwivedi

When it comes to location of jars to be decided, the thumb rule is that:

  1. Use a jar in the server lib location.
  2. If the jar is not available, include the same in the application's lib folder.
  3. To find a suitable Jars, system looks in the following repositories, in the order:

Bootstrap classes of your JVM

System class loader classes (described above)

/WEB-INF/classes of your web application /WEB-INF/lib/*.jar of

your web application $CATALINA_HOME/common/classes

$CATALINA_HOME/common/endorsed/*.jar

$CATALINA_HOME/common/i18n/*.jar

$CATALINA_HOME/common/lib/*.jar

$CATALINA_BASE/shared/classes

$CATALINA_BASE/shared/lib/*.jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!