• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Jboss3.0-tomcat4.03的配置(二)

发布: 2007-5-25 14:12 | 作者: 佚名 | 来源: jspcn | 查看: 62次 | 进入软件测试论坛讨论

领测软件测试网

一.Jboss3.0-Tomcat4.03的数据库的配置(以Oracle为例)


一、 请将classes12.zip加入classpath中去。
二、请参况hsqldb-service.xml文件编写Oracledb-service.xml文件
请打开serverdefaultdeploy目录下的hsqldb-service.xml文件,这就是一个Jboss3.0_Tomcat4.03下实现数据库连接的例子,它是连接hsql数据库的它的内容如下:
&lt ?xml version="1.0" encoding="UTF-8"? &gt

&lt !-- ===================================================================== -- &gt
&lt !-- -- &gt
&lt !-- JBoss Server Configuration -- &gt
&lt !-- -- &gt
&lt !-- ===================================================================== -- &gt

&lt !-- $Id: hsqldb-service.xml,v 1.2.2.5 2002/06/23 21:25:58 d_jencks Exp $ -- &gt


&lt server &gt

&lt !-- ==================================================================== -- &gt
&lt !-- New ConnectionManager setup for default hsql dbs -- &gt
&lt !-- Build jmx-api (build/build.sh all) and view for config documentation -- &gt
&lt !-- ==================================================================== -- &gt

&lt mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=hsqldbDS" &gt

&lt !-- Include a login module configuration named HsqlDbRealm.
Update your login-conf.xml, here is an example for a
ConfiguredIdentityLoginModule:

&lt application-policy name = "HsqlDbRealm" &gt
&lt authentication &gt
&lt login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required" &gt
&lt module-option name = "principal" &gtsa&lt /module-option &gt
&lt module-option name = "userName" &gtsa&lt /module-option &gt
&lt module-option name = "password" &gt&lt /module-option &gt
&lt module-option name = "managedConnectionFactoryName" &gtjboss.jca:service=LocalTxCM,name=hsqldbDS&lt /module-option &gt
&lt /login-module &gt
&lt /authentication &gt
&lt /application-policy &gt

NOTE: the application-policy name attribute must match
SecurityDomainJndiName, and the
module-option name = "managedConnectionFactoryName"
must match the object name of the ConnectionManager you are configuring here.
-- &gt
&lt !--uncomment out this line if you are using the DB2DbRealm above
&lt attribute name="SecurityDomainJndiName" &gtHsqlDbRealm&lt /attribute &gt
-- &gt

&lt depends optional-attribute-name="ManagedConnectionFactoryName" &gt
&lt !--embedded mbean-- &gt
&lt mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=hsqldbDS" &gt

&lt attribute name="JndiName" &gtDefaultDS&lt /attribute &gt
&lt attribute name="ManagedConnectionFactoryProperties" &gt
&lt properties &gt
&lt config-property name="ConnectionURL" type="java.lang.String" &gtjdbc:hsqldb:hsql://localhost:1476&lt /config-property &gt
&lt config-property name="DriverClass" type="java.lang.String" &gtorg.hsqldb.jdbcDriver&lt /config-property &gt
&lt config-property name="UserName" type="java.lang.String" &gtsa&lt /config-property &gt
&lt config-property name="Password" type="java.lang.String" &gt&lt /config-property &gt
&lt /properties &gt
&lt /attribute &gt

&lt !--Below here are advanced properties -- &gt
&lt !--hack-- &gt
&lt depends optional-attribute-name="OldRarDeployment" &gtjboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper&lt /depends &gt
&lt depends &gtjboss:service=Hypersonic&lt /depends &gt

&lt /mbean &gt
&lt /depends &gt
&lt depends optional-attribute-name="ManagedConnectionPool" &gt
&lt !--embedded mbean-- &gt
&lt mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=hsqldbDS" &gt

&lt attribute name="MinSize" &gt0&lt /attribute &gt
&lt attribute name="MaxSize" &gt50&lt /attribute &gt
&lt attribute name="BlockingTimeoutMillis" &gt5000&lt /attribute &gt
&lt attribute name="IdleTimeoutMinutes" &gt15&lt /attribute &gt
&lt !--criteria indicates if Subject (from security domain) or app supplied
parameters (such as from getConnection(user, pw)) are used to distinguish
connections in the pool. Choices are
ByContainerAndApplication (use both),
ByContainer (use Subject),
ByApplication (use app supplied params only),
ByNothing (all connections are equivalent, usually if adapter supports
reauthentication)-- &gt
&lt attribute name="Criteria" &gtByContainer&lt /attribute &gt
&lt /mbean &gt
&lt /depends &gt
&lt depends optional-attribute-name="CachedConnectionManager" &gtjboss.jca:service=CachedConnectionManager&lt /depends &gt

&lt depends optional-attribute-name="JaasSecurityManagerService" &gtjboss.security:service=JaasSecurityManager&lt /depends &gt

&lt attribute name="TransactionManager" &gtjava:/TransactionManager&lt /attribute &gt

&lt !--make the rar deploy! hack till better deployment-- &gt
&lt depends &gtjboss.jca:service=RARDeployer&lt /depends &gt

&lt /mbean &gt


&lt !-- Moved to end to test anonymous depends -- &gt

&lt mbean code="org.jboss.jdbc.HypersonicDatabase"
name="jboss:service=Hypersonic" &gt
&lt attribute name="Port" &gt1476&lt /attribute &gt
&lt attribute name="Silent" &gttrue&lt /attribute &gt
&lt attribute name="Database" &gtdefault&lt /attribute &gt
&lt attribute name="Trace" &gtfalse&lt /attribute &gt
&lt /mbean &gt

&lt /server &gt
在&lt !-- -- &gt之间没有用的一些说明,所以去掉这一些说明后经过改写一个存取oracle数据库的服务的XML的文件是Oracledb-service.xml
&lt ?xml version="1.0" encoding="UTF-8"? &gt

&lt server &gt

&lt mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=oracleDS" &gt


&lt depends optional-attribute-name="ManagedConnectionFactoryName" &gt
&lt !--embedded mbean-- &gt
&lt mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=oracleDS" &gt

&lt attribute name="JndiName" &gtOracleDS&lt /attribute &gt
&lt attribute name="ManagedConnectionFactoryProperties" &gt
&lt properties &gt
&lt config-property name="ConnectionURL" type="java.lang.String" &gtjdbc:oracle:thin:@cuipeng:1521:Ora8&lt /config-property &gt
&lt config-property name="DriverClass" type="java.lang.String" &gtoracle.jdbc.driver.OracleDriver&lt /config-property &gt
&lt config-property name="UserName" type="java.lang.String" &gtsystem&lt /config-property &gt
&lt config-property name="Password" type="java.lang.String" &gtmanager&lt /config-property &gt
&lt /properties &gt
&lt /attribute &gt

&lt depends optional-attribute-name="OldRarDeployment" &gtjboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper&lt /depends &gt
&lt /mbean &gt
&lt /depends &gt
&lt depends optional-attribute-name="ManagedConnectionPool" &gt
&lt !--embedded mbean-- &gt
&lt mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=oracleDS" &gt

&lt attribute name="MinSize" &gt0&lt /attribute &gt
&lt attribute name="MaxSize" &gt50&lt /attribute &gt
&lt attribute name="BlockingTimeoutMillis" &gt5000&lt /attribute &gt
&lt attribute name="IdleTimeoutMinutes" &gt15&lt /attribute &gt
&lt attribute name="Criteria" &gtByContainer&lt /attribute &gt
&lt /mbean &gt
&lt /depends &gt
&lt depends optional-attribute-name="CachedConnectionManager" &gtjboss.jca:service=CachedConnectionManager&lt /depends &gt

&lt depends optional-attribute-name="JaasSecurityManagerService" &gtjboss.security:service=JaasSecurityManager&lt /depends &gt

&lt attribute name="TransactionManager" &gtjava:/TransactionManager&lt /attribute &gt

&lt depends &gtjboss.jca:service=RARDeployer&lt /depends &gt

&lt /mbean &gt

&lt /server &gt
请大家对比两个文件的不同之外,很容易写出其它数据库的存取服务了,主要的是下面这个部分
&lt mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=oracleDS" &gt

&lt attribute name="JndiName" &gtOracleDS&lt /attribute &gt&lt !--这个地方是JNDI的名字在ejb或jsp中调用的是java:/OracleDS -- &gt
&lt attribute name="ManagedConnectionFactoryProperties" &gt
&lt properties &gt
&lt config-property name="ConnectionURL" type="java.lang.String" &gtjdbc:oracle:thin:@cuipeng:1521:ora8&lt /config-property &gt
&lt config-property name="DriverClass" type="java.lang.String" &gtoracle.jdbc.driver.OracleDriver&lt /config-property &gt
&lt config-property name="UserName" type="java.lang.String" &gtsystem&lt /config-property &gt
&lt config-property name="Password" type="java.lang.String" &gtmanager&lt /config-property &gt
&lt /properties &gt
&lt /attribute &gt
&lt depends optional-attribute-name="OldRarDeployment" &gtjboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper&lt /depends &gt
&lt /mbean &gt
还有就是各个部分的名字了name=oracleDS
三、测试数据的连接列子(我用的是jsp)
你必需要编写.war或.ear包来测试一个简易的做法就是:
一、 在deploy目录下建立oracle-test.war目录。
二、在oracle-test.war目录下建立WEB-INF目录,其中有两个文件
jboss-web.xml和web.xml
内容分别是
jboss-web.xml内容是
&lt jboss-web &gt
&lt /jboss-web &gt
web.xml内容是
&lt ?xml version="1.0"? &gt
&lt !DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" &gt

&lt web-app &gt
&lt /web-app &gt
三、在oracle-test.war目录下建立新文件index.jsp其内容是
&lt %@page contentType="text/html"% &gt
&lt %@ page import="java.sql.*, javax.sql.DataSource, javax.naming.InitialContext" % &gt

&lt h3 &gtTest Oracle DB&lt /h3 &gt

&lt %


InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:/OracleDS"); //注意这里哦和前面对应
Connection conn = ds.getConnection();


Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM TAB");


while ( rs.next() ) {
out.println( rs.getString("TNAME") + "&lt br &gt");
}

conn.close();

% &gt
 四、请访问http://localhost:8080/oracle-test
一切都测试OK的,如果有什么不对的地方请指哦,我也是学习的。这是一个快速的配置方法,在过一些时间我会把每个属性表示什么给大家说说.

二.综合

Apache,Jboss3.0-Tomcat4.03整合
Operator System: Windows 2000 server 2
Application server: Jboss3.0-tomcat4.03
DB: Oracle8.17
JDK: jdk1.31
Web Server Apache1.3
一、 首先安装好Apache,Jboss3.0-Tomcat4.03我安装在E:Jboss3.0_Tomcat4.03和E:WebServerApache目录下
二、编缉tocmat-service.xml文件如下
&lt ?xml version="1.0" encoding="UTF-8"? &gt
&lt !-- Set catalina.home to the location of the Tomcat-4.x dist.
The default value is that of the JBoss/Catalina bundle where the
jakarta-tomcat-4.0.3-LE-jdk14 is included as jboss_dist/catalina
-- &gt
&lt !DOCTYPE server [
&lt !ENTITY catalina.home "../catalina" &gt
] &gt

&lt !-- The service configuration for the embedded Tomcat4 web container
-- &gt
&lt server &gt

&lt classpath codebase="file:&catalina.home;/common/lib/" archives="*"/ &gt
&lt classpath codebase="file:&catalina.home;/server/lib/" archives="*"/ &gt
&lt classpath codebase="file:&catalina.home;/bin/" archives="*"/ &gt
&lt classpath codebase="file:&catalina.home;/lib/" archives="*"/ &gt
&lt classpath codebase="." archives="tomcat4-service.jar"/ &gt

&lt mbean code="org.jboss.web.catalina.EmbeddedCatalinaServiceSX"
name="jboss.web:service=EmbeddedCatalinaSX" &gt
&lt attribute name="CatalinaHome" &gt&catalina.home;&lt /attribute &gt

&lt !-- Uncomment this if you want interval snapshot for the
session clustering.
&lt attribute name="SnapshotMode" &gtinterval&lt /attribute &gt
&lt attribute name="SnapshotInterval" &gt2000&lt /attribute &gt
-- &gt
&lt attribute name="Config" &gt
&lt Server &gt
&lt Service name = "JBoss-Tomcat" &gt
&lt Engine name="MainEngine" defaultHost="localhost" &gt
&lt Logger className = "org.jboss.web.catalina.Log4jLogger"
verbosityLevel = "trace" category = "org.jboss.web.localhost.Engine"/ &gt
&lt Host name="localhost" &gt
&lt Valve className = "org.apache.catalina.valves.AccessLogValve"
prefix = "localhost_access" suffix = ".log"
pattern = "common" directory = "../server/default/log" / &gt
&lt DefaultContext cookies = "true" crossContext = "true" override = "true" / &gt
&lt /Host &gt
&lt /Engine &gt

&lt !-- A HTTP Connector on port 8080 -- &gt
&lt Connector className = "org.apache.catalina.connector.http.HttpConnector"
port = "8080" minProcessors = "3" maxProcessors = "10" enableLookups = "true"
acceptCount = "10" debug = "0" connectionTimeout = "60000"/ &gt
&lt Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" / &gt
&lt /Service &gt
&lt /Server &gt
&lt /attribute &gt
&lt /mbean &gt

&lt /server &gt
其中这里是最重要的:
&lt Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" / &gt
和Apache的连接在这里定义的。
三、下载mod_jk.dll从这里下载http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.3/bin/win32/i386/mod_jk.dll
下载后考到Apache的modules目录下。
四、编辑 Apache的conf目录下的http.conf文件。在最后加入如下的几行
LoadModule jk_module modules/mod_jk.dll
&lt IfModule mod_jk.c &gt
JkWorkersFile conf/workers.properties
JkLogFile logs/jk.log
JkLogLevel warn
JkMount /*.jsp ajp13
JkMount /web/* ajp13
JkMount /jmx-console/* ajp13
&lt /IfModule &gt
//这个加的东东你可以自己跟自己的情况变化的
其中都在/jmx-console/和/web/都在Jboss3.0-Tomcat4.03发布的web应用所以在你添加这些前至少可以通过8080访问这/jmx-console/和/web/的及http://localhost:8080/jmx-console/和http://localhost:8080/web/是成功的。
四、保存下列为workers.properties文件
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
worker.ajp13.cachesize
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp13
上面这些是实现的最小元素。当然你是可以加的啊。面conf/http.conf中指定这个文件如JkWorkersFile conf/workers.properties我放在了conf目录下,及和http.conf同目录。
起apache和jboss-tomcat后,http://localhost/jmx-console/和http://localhost/web/是成功的浏览,一切OK

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网