是否有必要在资源标记中提及归档的名称? [英] Isn't it necessary to mention the name of archive in the Resource tag?

查看:101
本文介绍了是否有必要在资源标记中提及归档的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使用 Tomcat 连接到 derby 数据库,我下载了核心Apache Derby数据库引擎(版本:10.9.1.0)的jar。我将这个jar文件保存在Tomcat中的 lib 文件夹下。

To connect to derby database while using Tomcat, I downloaded the jar of core Apache Derby database engine (version : 10.9.1.0). I kept this jar file under the lib folder in Tomcat.

现在我被要求在 context.xml Tomcat

Now I was told to add the following in context.xml of Tomcat.

<Resource name="jdbc/PollDatasource" auth="Container" type="javax.sql.DataSource"
    driverClassName="org.apache.derby.jdbc.EmbeddedDriver" 
    url="jdbc:derby://localhost:1527/polldatabase;create=true"
    username="suhail" password="suhail"
    maxActive="20" maxIdle="10" maxWait="-1" />




    • What does this tag do ? I mean what it is meant for ?

      虽然我下载的Jar文件包含模式 org.apache.derby.jdbc.EmbeddedDriver 在这个标签中我提到我下载的jar?是否需要在标记中添加归档名称?

      Though the Jar file i downloaded contains the pattern org.apache.derby.jdbc.EmbeddedDriver where in this tag I mention the jar that I downloaded? Isn't there a need to add the name of archive in the tag ?

      推荐答案

      一旦您将一个jar放在Tomcat lib文件夹下,Tomcat会自动加载它并将其放在类路径中,这样Tomcat上运行的所有应用程序都知道这个jar。

      Once you put a jar under the Tomcat lib folder, Tomcat will automatically load it and put it in the classpath so all applications running on Tomcat know about this jar.

      XML中的定义仅仅意味着你定义了一个数据源。在应用程序服务器中使用数据源来管理数据库连接池,因此您不必使用数据库连接池,它是优先使用的方式,而不是使用纯JDBC。

      The definition in the XML simply means you defined a datasource. A datasource is used in application servers to manage DB connection pools so you don't have to, it is the preffered way instead of using plain JDBC.

      定义: driverClassName =org.apache.derby.jdbc.EmbeddedDriver因为你把包含这个类的驱动程序jar,在lib文件夹中,它将知道在哪里找到它,而不需要告诉它在哪里的jar。

      In the xml you defined : driverClassName="org.apache.derby.jdbc.EmbeddedDriver" and since you put the driver jar that contains this class, in the lib folder, it will know where to look for it without you needing to tell it where the jar is.

      请注意,将jar放在Tomcat lib下并不总是最好的解决方案,因为像我说的, tomcat下的所有应用程序都会知道这个jar,如果有一个应用程序已经使用了不同版本的jar,可能会导致冲突。

      Please note that putting the jar under Tomcat lib is not always the best solution since, like i said, all applications under tomcat will know of this jar, and if there is an application that already uses this jar with a different version, it might cause conflicts.

      是把jar放在WEB-INF / lib下,这样只有这个应用程序知道这个jar。

      A better solution might be to put the jar under WEB-INF/lib and that way only this application knows of the jar.

      这篇关于是否有必要在资源标记中提及归档的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆