明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

Apache2.0.47與Tomcat4.1.27整合過程

[摘要]參考了網(wǎng)上很多資料,發(fā)現(xiàn)大都或多或少有些小問題,現(xiàn)把我的整合過程貼出來,供大家參考。一、準備需要以下程序:j2sdk1.4.2_01,apache-2.0.47,jakarta-tomcat-4.1...
參考了網(wǎng)上很多資料,發(fā)現(xiàn)大都或多或少有些小問題,現(xiàn)把我的整合過程貼出來,供大家參考。

一、準備

需要以下程序:
j2sdk1.4.2_01,apache-2.0.47,jakarta-tomcat-4.1.27,以及mod_jk2-2.0.43.dll
以上程序都可以在sun和apache.org下載到。
j2sdk1.4.2_01 : http://java.sun.com/j2se/1.4.2/download.html選J2SE v 1.4.2_01 的SDK
apache-2.0.47 : http://apache.linuxforum.net/dist/httpd/binaries/win32/apache_2.0.47-win32-x86-no_ssl.exe
tomcat-4.1.27 : http://apache.linuxforum.net/dist/jakarta/tomcat-4/binaries/jakarta-tomcat-4.1.27.exe
mod_jk2-2.0.43.dll : http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk2/release/v2.0.2/bin/win32/mod_jk2-2.0.43.dll
注意下載的jk2文件名:mod_jk2-2.0.43.dll,而網(wǎng)上還有mod_jk-2.0.4x.dll,這是jk而不是jk2

二、安裝
假設(shè)j2sdk1.4.2_01安裝到D:\j2sdk1.4.2_01下,用[Java_install_dir]代表此路徑
apache-2.0.47安裝到D:\Program Files\Apache Group\Apache2,用[Apache_install_dir]代表此路徑,服務(wù)端口為80
jakarta-tomcat-4.1.27安裝到D:\Program Files\Apache Group\Tomcat 4.1,用[Tomcat_install_dir]代表此路徑,服務(wù)端口為8080
在系統(tǒng)環(huán)境變量里添加JAVA_HOME和TOMCAT_HOME分別為以上路徑,再修改CLASS_PATH,添加%JAVA_HOME%\lib;%TOMCAT_HOME%\bin;
安裝時把Apache和Tomcat都設(shè)置為后臺服務(wù)方式運行。

三、配置

1. 在Apache2中安裝mod_jk2-2.0.43.dll
將mod_jk2-2.0.43.dll拷貝到[Apache_install_dir]/modules目錄中

編輯[Apache_install_dir]/conf/httpd.conf配置文件,在文件最后添加如下一行:
LoadModule jk2_module modules/mod_jk2-2.0.43.dll
2. 配置Apache端
[在Apache_install_dir]/conf目錄中新建文件workers2.properties,內(nèi)容如下:

# Define the comunication channel
[channel.jni:jni]
info=The jni channel, used if tomcat is started inprocess

# Define the parameters for the Java Virtual Machine
[vm:]
info=Parameters used to load a JVM in the server process
OPT=-Djava.class.path=[Tomcat_install_dir]\bin\tomcat-jni.jar;[Tomcat_install_dir]\bin\tomcat.jar
OPT=-Dtomcat.home=[Tomcat_install_dir]
OPT=-Dcatalina.home=[Tomcat_install_dir]
OPT=-Xmx128M

# JNI worker startup handler
[worker.jni:onStartup]
info=Command to be executed by the VM on startup. This one will start tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=start
stdout=[Apache_install_dir]\logs\stdout.log
stderr=[Apache_install_dir]\logs\stderr.log

# JNI worker shutdown handler
[worker.jni:onShutdown]
info=Command to be executed by the VM on shutdown. This one will stop tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=stop

# Map the Tomcat examples webapp to the Web server uri space
[uri:/examples/*]
info=Map the whole webapp

#注:
#網(wǎng)上有資料OPT=-Djava.class.path是指向\lib\,實際上安裝目錄下并無\lib目錄,如不修改會出現(xiàn)java.lang.NoClassDefFoundError: org/apache/jk/apr/TomcatStarter異常
#把[Tomcat_install_dir]和[Apache_install_dir]換成實際安裝路徑,其余不用做任何改動

3. 配置Tomcat端
修改[Tomcat_install_dir]/conf/jk2.properties,用以下內(nèi)容替換原來內(nèi)容:

# Set the desired handler list
handler.list=apr,request,container,channelJni

# Enable jni use channelJni directive
apr.jniModeSo=[Apache_install_dir]\modules\mod_jk2-2.0.43.dll

# If set to inprocess the mod_jk2 will Register natives itself
# This will enable the starting of the Tomcat from mod_jk2
# If you wish to start the Tomcat from inside web server then
# you don′t need any above directive. Here is shown the default
# value for the apr that you can ommit
apr.jniModeSo=inprocess

#注:
#把[Tomcat_install_dir]和[Apache_install_dir]換成實際安裝路徑,其余不用做任何改動
#這種方式使用JNI通道,因此運行Apache時會通過JNI直接在后臺啟動Tomcat。

四、測試:
啟動Apache
看http://localhost/examples/jsp/
如顯示正確內(nèi)容則整合成功!
如不成功請檢查[Apache_install_dir]\logs\stdout.log和[Apache_install_dir]\logs\stderr.log日志,看是什么錯誤,根據(jù)錯誤提示進行修改。