WAS CE命令行配置DB2数据源及引用

环境:Redhat5.4, WASCE3.0

与WAS的区别非常大,毕竟虽然叫WASCE,但根本不是WAS,基本上所有的操作全是通过deploy命令加计划文件执行的,对于配置DB2数据源,首先要把db2jcc.jar和db2_license_cu.jar放到lib目录下面,然后编写计划文件,如下:

<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.2">
<dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
<dep:moduleId>
<dep:groupId>console.dbpool</dep:groupId>
<dep:artifactId>DBRS</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies>
<dep:dependency>
<dep:groupId>com.ibm.db2</dep:groupId>
<dep:artifactId>db2jcc</dep:artifactId>
<dep:type>jar</dep:type>
</dep:dependency>
<dep:dependency>
<dep:groupId>com.ibm.db2</dep:groupId>
<dep:artifactId>db2jcc_license_cu</dep:artifactId>
<dep:type>jar</dep:type>
</dep:dependency>
</dep:dependencies>
</dep:environment>
<resourceadapter>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
<connectiondefinition-instance>
<name>DBRS</name>
<config-property-setting name="TraceFile"/>
<config-property-setting name="UserName">username</config-property-setting>
<config-property-setting name="DatabaseName">Database</config-property-setting>
<config-property-setting name="Password">******</config-property-setting>
<config-property-setting name="ServerName">Server Address</config-property-setting>
<config-property-setting name="PortNumber">默认是50000</config-property-setting>
<connectionmanager>
<local-transaction/>
<single-pool>
<max-size>10</max-size>
<min-size>0</min-size>
<match-one/>
</single-pool>
</connectionmanager>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
</connector>


配置文件写好后,执行如下命令:

./deploy.sh --user user --password password deploy WASCEHOME/repository/org/tranql/tranql-connector-db2-xa/1.7/tranql-connector-db2-xa-1.7.rar ../计划文件.xml

这样便配置好了一个名为DBRS的数据源,接下来就是如何让Web应用可以通过JNDI查找到了,同样是通过deploy加计划文件来实现,编写计划文件,如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1">
    <environment>
        <moduleId>
            <artifactId>Application</artifactId>
        </moduleId>
        <dependencies>
            <dependency>
                <groupId>console.dbpool</groupId>
                <artifactId>DBRS</artifactId>
            </dependency>
        </dependencies>
    </environment>
    <context-root>/WebContext</context-root>
<resource-ref>
        <ref-name>jndi</ref-name>
        <resource-link>DBRS</resource-link>
    </resource-ref>
</web-app>


之后修改应用的web.xml文件,加入如下配置:

<resource-ref>

<res-ref-name>jndi</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

<res-sharing-scope>Shareable</res-sharing-scope>

</resource-ref>


最后运行下面的命令:

 ./deploy.sh --user user--password password deploy ../war包 ../计划文件.xml


完成部署应用的同时配置了JNDI引用,如此就可以通过JNDI查找到配置好的数据源了,有些以前直接写JNDI的地方,可能需要改了java:comp/env/JNDI才可以找到。

你可能感兴趣的:(WAS CE命令行配置DB2数据源及引用)