明辉站/技术开发/内容

Apache2.0.47与Tomcat4.1.27整合过程

技术开发2023-08-15 阅读
[摘要]参考了网上很多资料,发现大都或多或少有些小问题,现把我的整合过程贴出来,供大家参考。一、准备需要以下程序: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,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,而网上还有mod_jk-2.0.4x.dll,这是jk而不是jk2

二、安装
假设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]代表此路径,服务端口为80
jakarta-tomcat-4.1.27安装到D:\Program Files\Apache Group\Tomcat 4.1,用[Tomcat_install_dir]代表此路径,服务端口为8080
在系统环境变量里添加JAVA_HOME和TOMCAT_HOME分别为以上路径,再修改CLASS_PATH,添加%JAVA_HOME%\lib;%TOMCAT_HOME%\bin;
安装时把Apache和Tomcat都设置为后台服务方式运行。

三、配置

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,内容如下:

# 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

#注:
#网上有资料OPT=-Djava.class.path是指向\lib\,实际上安装目录下并无\lib目录,如不修改会出现java.lang.NoClassDefFoundError: org/apache/jk/apr/TomcatStarter异常
#把[Tomcat_install_dir]和[Apache_install_dir]换成实际安装路径,其余不用做任何改动

3. 配置Tomcat端
修改[Tomcat_install_dir]/conf/jk2.properties,用以下内容替换原来内容:

# 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/
如显示正确内容则整合成功!
如不成功请检查[Apache_install_dir]\logs\stdout.log和[Apache_install_dir]\logs\stderr.log日志,看是什么错误,根据错误提示进行修改。

……

相关阅读