简体   繁体   English

JDBC驱动程序是否应包含在WAR中?

[英]Should JDBC drivers be included in a WAR?

We have a commercial software product under development. 我们正在开发一种商业软件产品。 It supports Oracle, MySQL, and SQL*Server backends (we also use H2 for testing). 它支持Oracle,MySQL和SQL * Server后端(我们也使用H2进行测试)。 We do our integration testing against those different database using JDBC drivers of a specific version. 我们使用特定版本的JDBC驱动程序对这些不同的数据库进行集成测试。 Maven handles all this beautifully. Maven处理这一切都非常漂亮。

When packaging the application as a WAR, is it ok if we include the JDBC drivers? 将应用程序打包为WAR时,如果我们包含JDBC驱动程序是否可以? What is the standard practice? 什么是标准做法?

Since we don't know which database could be used ahead of time, we'd have to include them all. 由于我们不知道哪个数据库可以提前使用,因此我们必须将它们全部包含在内。 The targeted servlet containers are Tomcat and Jetty, but some customers will also want to run within WebSphere and JBoss. 目标servlet容器是Tomcat和Jetty,但是一些客户也希望在WebSphere和JBoss中运行。

So the servlet contains and application servers come with their own JDBC drivers? 那么servlet包含和应用程序服务器自带的JDBC驱动程序? Will ours conflict? 我们会发生冲突吗 Another concern is that we have developed and tested with one version of the driver and if a customer uses another version, we may have problems. 另一个问题是我们已经开发并测试了一个版本的驱动程序,如果客户使用其他版本,我们可能会遇到问题。

Currently we use Spring data source beans, but are in the process of moving to JNDI lookup for the datasource. 目前我们使用Spring数据源bean,但正在转向数据源的JNDI查找。

So the servlet contains and application servers come with their own JDBC drivers? 那么servlet包含和应用程序服务器自带的JDBC驱动程序?

Some do (eg WebLogic). 有些人(例如WebLogic)。

Will ours conflict? 我们会发生冲突吗

They shouldn't. 他们不应该。 Not sure yours will be picked when creating an standalone connection pool at the application level though (it all depends on the classloader delegation mode). 不确定在应用程序级别创建独立连接池时会选择您的(这完全取决于类加载器委派模式)。

Another concern is that we have developed and tested with one version of the driver and if a customer uses another version, we may have problems. 另一个问题是我们已经开发并测试了一个版本的驱动程序,如果客户使用其他版本,我们可能会遇到问题。

Have a list of supported versions. 有一个支持的版本列表。

Currently we use Spring data source beans, but are in the process of moving to JNDI lookup for the datasource. 目前我们使用Spring数据源bean,但正在转向数据源的JNDI查找。

If by this you mean using the connection pool provided by an application server, drivers must be installed at the container level , not at the application level. 如果这意味着使用应用程序服务器提供的连接池,则必须在容器级别而不是在应用程序级别安装驱动程序。 And this somehow ends the discussion. 这以某种方式结束了讨论。

In most of the applications, JDBC drivers aren't shipped as part of the application. 在大多数应用程序中,JDBC驱动程序不作为应用程序的一部分提供。

If you do ship JDBC drivers, that means that you have to give drivers for all the database you want to support. 如果您运送JDBC驱动程序,则意味着您必须为要支持的所有数据库提供驱动程序。 It add a lot of unnecessary libraries. 它添加了许多不必要的库。

Just don't add any driver, and tell the user to put the relevant JAR file in the server libraries if needed. 只是不添加任何驱动程序,并告诉用户在需要时将相关的JAR文件放在服务器库中。

除了在war文件中包含驱动程序的技术优点之外,您还应检查驱动程序的许可,并确保它可由第三方分发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM