部落客廣告聯播

顯示具有 tomcat 標籤的文章。 顯示所有文章
顯示具有 tomcat 標籤的文章。 顯示所有文章

2010年6月30日 星期三

2009年12月11日 星期五

WebApp從tomcat遷移到jboss的data source問題

最近將WebApp從tomcat包成war檔移到jboss上,但卻履出現deploy failed失敗訊息,
後來發現是data source問題,若web.xml裡面有<resource-ref>參考到資料來源的話,
就要多一個jboss-web.xml設定jndi連結,詳細請參考:
JBoss deployment failure - missing resource-ref element in web.xml
How to configure the Jira DataSource on JBoss

2009年9月18日 星期五

啟用tomcat內建之HTTPS

1. 到 %JAVA_HOME%\bin目錄, 執行:
keytool -genkey -alias tomcat -keyalg RSA
輸入keystore密碼: **********
您的名字與姓氏是什麼?
[Unknown]: Lili.Wang
您的組織單位名稱是什麼?
[Unknown]: myCompany
您的組織名稱是什麼?
[Unknown]: myCompany
您所在的城市或區域名稱是什麼?
[Unknown]: Taipei
您所在的州或省份名稱是什麼?
[Unknown]: Taiwan
該單位的兩字母國家代碼是什麼
[Unknown]: TW
CN=Lili.Wang, OU=myCompany, O=myCompany, L=Taipei, ST=Taiwan, C=TW正確嗎?
[否]: y

輸入的主密碼
(如果和 keystore 密碼相同,按回車): {{直接按enter}}

2. 編輯 tomcat 的conf\server.xml找到下面區段,取消註解,並加上紅字部分,紅字雙引號內的值與第一步的密碼要相同
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true" keystorePass="**********"
clientAuth="false" sslProtocol="TLS" />

3. 重啟Tomcat

4. 開啟瀏覽器 https://localhost:8443 ,測試是否成功

(P.S. 要注意的是如果用admin1身份執行tomcat,則就要以admin1登入執行
keytool -genkey指令)

2009年9月17日 星期四

Tomcat 開啟 Access Log

Access Log會紀錄哪個時間哪個IP連入tomcat哪個網址,
tomcat是使用VALV的機制達成(類似filter),預設並無開啟,
若要開啟則須 修改conf\server.xml,找到內有一段
directory="logs" prefix="localhost_access_log." suffix=".log"
pattern="common" resolveHosts="false"/>
把前後包夾的註解符號拿掉後,存檔,重啟tomcat,便會在log目錄裡面看到
localhost_access_log.開頭的紀錄檔了。

2009年8月19日 星期三

tomcat server.xml設定全域的DataSource / mailSession資源

所謂全域就是指同一tomcat中的所有context

1. 在server.xml的<globalnamingresources>中加入新的<resource>元素。
2. 在context.xml的<context>中加入 <resourcelink name="mail/MailSession" global="mail/MailSession" type="javax.sql.DataSource"></resourcelink>

2009年7月20日 星期一

Eclipse + tomcat 遠端Debug

[Tomcat端]
修改catalina.bat
set JAVA_OPTS=%JAVA_OPTS% -Xmx256m 這行後面加上
-Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888

[Eclipse端]
自己google一下吧

2008年7月15日 星期二

TOMCAT 指定使用其他JDK

在tomcat\bin\的startup.bat和shutdown.bat的最開頭加上兩行:

set JAVA_HOME="c:\jre_dir"
set CATALINA_HOME="D:\tomcat_dir"

2008年6月7日 星期六

tomcat DBCP 與 MySQL

故事是這樣的:
我的程式直接使用MySQL connector/J JDBC Driver連接資料庫操作都很正常 ,
但透過Tomcat配置的data source(DBCP)取得connection來對資料庫操作 ,
總是不定時的會出現 'No operation allowed after connection closed' 錯誤訊息,
意思是connection已經被關閉掉了,
也換了最新的JDBC Driver, 也換過Tomcat 版本,怎麼試結果都一樣,還是錯,
查了許久也作了trace, 這connection並不是我的程式關掉的,
同時還將程式移到了websphere 並使用websphere中的connection pool, 結果是不會發生這樣的錯誤的。
那麼剩下的兩個可能便是:

  1. DBCP程式關掉的
  2. MySQL server端關掉的

OK, 網上拜神(Google), 搜到許多的線索, 有人說connection url要有autoReconnect=true選項,但這僅適用於連線時間超過八小時者。bug database有類似問提,但早就已經修正好了。 也有人說要改MySQL server的my.ini (my.cnf) ,恩...改了可是還是錯。

OK...上面都是廢言....
解決方案是在 tomcat server.xml中的<context>其內的<resource>標籤(設定DataSource用的)要多一個 屬性 validationQuery="select 1" , 之後便不會再三不五時拿到被關掉的connection了,測底解決。

----------------------------------------------------------------------------------------------

為何如此能解決呢??
我猜想大概是多了validationQuery後, DBCP在做相關資料庫操作時,
若該connection沒被客戶端程式(也就是我的程式)手動關閉connection ,也沒被DBCP關閉connection ,
會先用validationQuery的sql檢查, 是否連線被MySQL server端中斷了 ,如果是就自動再從MySQL server取得一個新的connection。
以上僅是小弟猜測, 因為對DBCP內部運作並不是很熟悉 ,所以如有人能回答請不吝提供正確答案...

-------------------------------------------------------------------------------------------

但... 問題來了....
如果以上我的猜測是正確的..... 那麼DBCP自動從MySQL server再次取得新的connection , 那麼也就代表了我之前被MySQL server端無端close掉的connection若是transaction的(autoCommit=false)不就無端的被中斷掉了,而且我也不會得知..... +.+ \\\
,這樣實在太太太不合理的.....................

所以說呢無端斷線問題暫時解決, 但關於transaction的疑問, 不知有哪位先進可以回答呢??

2008年5月7日 星期三

Tomcat Get亂碼

使用Get出去的資料在下一頁接收會變亂碼:
1. 在程式中先將中文parameter value使用(url+utf8) encoder編碼
2. 在tomcat 的server.xml,
<connector debug="”0″" port="”8080″" maxthreads="”150″" minsparethreads="”25″" maxsparethreads="”75″" enablelookups="”false”" redirectport="”8443″" acceptcount="”100″" connectiontimeout="”20000″" disableuploadtimeout="”true”" uriencoding="utf-8" />

2008年3月15日 星期六

Quartz使用JDBCDatasoruceTX使用tomcat datasource設置檔範例

Quartz使用JDBCDatasoruceTX使用tomcat datasource設置檔範例
[quartz.properties]


# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#

org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

# org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.CloudscapeDelegate
org.quartz.jobstore.dataSource = MailerJ
org.quartz.jobStore.useProperties = true
org.quartz.dataSource.MailerJ.jndiURL = java:comp/env/jdbc/JMailer
org.quartz.jobStore.dataSource = MailerJ

2007年9月30日 星期日

JSP custom tag library在OC4J中的使用注意事項(Notifications on using JSP Tag Library in OC4J)

在Tomcat上跑JSP常寫些custom tag lib如下:<myLib:myTag attribute1=" <%=request.getParameter("param") %> " />但在OC4J竟然會解析錯誤,無法解譯成java檔。
這真是令我想不透。


經過一番追查,改成如下:<myLib:myTag attribute1=' <%=request.getParameter("param") %> ' />
竟然就可以了。

都是雙引號在作怪。

2007年8月8日 星期三

Tomcat JDBC DataSource組態注意

在Tomcat中設定server.xml來組態設定一或多組DataSource,除了可以從JNDI位置取得該資料來源外,還有Connection Pooling的優點。
但關於Connection Pool設定若是不當,輕則效能不彰、重則導致無法取得資料庫連線而造成程式錯誤。
下面是Tomcat 官方文件關於在server.xml設定DataSource的範例:


<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<!-- username and password: MySQL dB username and password for dB connections -->
<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->

<!-- url: The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
</context>



其中注意兩個參數:

  • maxActive: 代表Pool可容納Connection的最大數量
  • maxIdlel:代表閒置時保留在Pool的Connection數量

親身經歷的事--在連線數使用超過maxActive時,後面取得Connection都為null,導致無法取得資料,造成程式錯誤!