问题
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