Isn't it necessary to mention the name of archive in the Resource tag?

女生的网名这么多〃 提交于 2019-12-13 03:54:15

问题


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.

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 ?

  • 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 ?


回答1:


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.

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.

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.

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.

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



来源:https://stackoverflow.com/questions/11519715/isnt-it-necessary-to-mention-the-name-of-archive-in-the-resource-tag

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