TOMCAT 6.0.14 DBOC 安裝記錄

12月 17, 2007

緣起: 我發現TOMCAT 討論區的資料都有些過時了. 絕少有論論新版的DBOC 的安裝方法. 繞了好大一圈查了不少心得分享(大部份是舊的), 實在解決不了問題.

先說說我的安裝過程好了. 我是依循官方的文件做的.但是畢竟是官方文件. 有些小細節是沒有提及的. 不過還是請各位參考一下. 以下是官方網站的連結.

http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

要特別注意這段話:
Please note that JNDI resource configuration changed somewhat between Tomcat 5.0.x and Tomcat 5.5.x. You will most likely need to modify older JNDI resource configurations to match the syntax in the example below in order to make them work in Tomcat 6.x.x.

當然光看完這段話也是一頭霧水.解決不了問題. 接下來請看看這段的說明
http://wiki.apache.org/tomcat/FAQ/Deployment
其中提到:
Why does tomcat 5 create context configuration files?

Unlike tomcat 4.x, tomcat 5.x creates context configuration files for you in its conf/[Engine name]/[Host name] directory. This is part of the change in tomcat's configuration mechanism from version 4.x to make overall configuration more robust, flexible, and enterprise-friendly. Note, however, that this has changed the recommended deployment practices for web applications. These context configuration files are created by tomcat, but not removed by tomcat, because the user may have changed them or other files in the conf directory. The suggested practice for tomcat 5 is to place context configuration files in the META-INF/context.xml directory of your webapp, and use Tomcat's Manager webapp to deploy/undeploy your applications. More details can be found here: [WWW] MARC Archive

也就是說原本在5.5版 .... 原本是被放在 c:\tomcat \conf\Server.xml 現在到了 6.0 卻被移出到 c:\tomcat\webapps\META-INF 並獨立出來為一單一的 context.xml 檔案

接下來請回到http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html 繼續看下去.
MySQL DBCP Example

0. Introduction
這部份改一下. 我的測試平台跟sample 有點不一樣.
MySQL 5.0.45
Connector/J 5.1.5 (the official JDBC Driver)mysql-connector-java-5.1.5-bin.jar
tomcat 6.0.14
Product Version: NetBeans IDE 6.0 (Build 200711261600)
Java: 1.6.0_03; Java HotSpot(TM) Client VM 1.6.0_03-b05
System: Windows XP version 5.1 running on x86; MS950; zh_TW (nb)
Userdir: C:\Documents and Settings\yitafan\.netbeans\6.0

1. MySQL configuration
這部份沒什麼特別的. 請你把它改為自己mysql server 上面的有效帳號就好

2.2. Context configuration

Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context.
這裏就要注意了 要把這下列的sample 貼到
c:\tomcat\webapps\META-INF\context.xml

3. web.xml configuration

Now create a WEB-INF/web.xml for this test application.
這部份也是把官網的sample 搬到你的 c:\tomcat\webapps\WEB-INF\web.xml

4. Test code

Now create a simple test.jsp page for use later.
這個測試用的 test.jsp 就放到 c:\tomcat\webapps

這部份有用到JSTL 請使用 jakarta-taglibs-standard-1.1.2
解壓縮後,把LIB目錄下的jstl.jar 跟 standard.jar 丟到 C:\tamcat\webapps\WEB-INF\LIB 目錄下即可

注意事項. 以上目錄只是便於說明 c:\tamcat\webapps 請自行換置成您的安裝路徑. 至於 webapps 我是用官方sample的預設DBTest

後記: 跑是跑起來了 不過.我不知如何查看DBOC 連結池的狀態. 有懂這方面的朋友們.再麻煩你們指點了. 若我的解說有什麼疑問也請留言. 我會就我所了解的來跟您解釋. 若有錯誤請不吝指教
blog comments powered by Disqus