1:安装好jboss-4.2.3.GA(已经集成了EJB3)
2:配置环境变量(如果与myeclipse搭配使用则不配置也可)JBoss_HOME=C:\jboss4GA;path: 增加: C:\jboss4GA\bin;
3:拷贝数据库驱动包我这里是ojdbc14.jar到指定目录:jboss4GA\server\default\lib下
4:将开发需要引用到的包copy到jboss4GA\client目录下
5:在目录jboss4GA\server\default\deploy下新建一个oracle-ds.xml数据源文件,也可以从D:\jboss-4.2.3.GA\docs\examples\jca下copy一个-ds我这里是oracle-ds.xml文件配置文件稍作修改即可注意这里必须以-ds结尾否则jboss不能识别为数据源配置文件;配置文件具体内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- JBoss Server Configuration -->
<!-- $Id: oracle-ds.xml 71535 2008-04-01 07:05:03Z [email protected] $ -->
<!-- Datasource config for Oracle originally from Steven Coy -->
<datasources>
<local-tx-datasource>
<!-- jndi名这是一个唯一的标示 -->
<jndi-name>myoraclejndi</jndi-name>
<!-- 数据驱动链接地址 -->
<connection-url>jdbc:oracle:thin:@localhost:1521:myoracle</connection-url>
<!--
Here are a couple of the possible OCI configurations.
For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm
<connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
or
<connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>
Clearly, its better to have TNS set up properly.
-->
<!-- 驱动类 -->
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>qhit</user-name>
<password>admin</password>
<!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
<!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
<!-- Checks the Oracle error codes and messages for fatal errors -->
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<!-- 配置数据库类型我这里配的oracle10g -->
<metadata>
<type-mapping>Oracle10g</type-mapping>
</metadata>
<!-- D:\jboss-4.2.3.GA\server\default\conf下的login-config.xml登录配置中application-policy配置的 名称标示必须与security-domain值对应-->
<security-domain>OracleDbRealm</security-domain>
</local-tx-datasource>
</datasources>
6:配置jboss-4.2.3.GA\server\default\conf\standardjbosscmp-jdbc.xml文件
<!-- 对应Oracle-ds.xml文件中的jndi-name属性值 -->
<datasource>java:/myoraclejndi</datasource>
对应
<jndi-name>myoraclejndi</jndi-name>
<!-- 对应Oracle-ds.xml文件中的type-mapping属性值 -->
<datasource-mapping>Oracle10g</datasource-mapping>
<type-mapping>Oracle10g</type-mapping>
7:配置jboss-4.2.3.GA\server\default\conf\login-config.xml在文件末尾追加以下代码
<!-- OracleDbRealm对应Oracle-ds.xml中的security-domain值-->
<application-policy name = "OracleDbRealm">
<authentication>
<login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<!-- myoraclejndi对应Oracle-ds.xml中的jndi-name值-->
<module-option name ="principal">myoraclejndi</module-option>
<!-- 数据库用户名与密码-->
<module-option name ="userName">qhit</module-option>
<module-option name ="password">admin</module-option>
<module-option name ="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=myoraclejndi
</module-option>
</login-module>
</authentication>
</application-policy>
Ok,至此配置全部搞定了,接下来只需要启动看效果即可;叫你老婆出来看上帝吧;没配错的话就可以执行了