- weli@power:~/projs/jboss-as-7.1.1.Final$ ls
- LICENSE.txt bundles jboss-modules.jar
- README.txt copyright.txt modules
- appclient docs standalone
- bin domain welcome-content
weli@power:~/projs/jboss-as-7.1.1.Final$ ls LICENSE.txt bundles jboss-modules.jar README.txt copyright.txt modules appclient docs standalone bin domain welcome-content
我们进到modules目录,创建postgres的目录:
- mkdir -p org/postgresql/main
mkdir -p org/postgresql/main
进入到创建好的目录,从Postgresql的网站下载所需的jdbc库,我下载的是postgresql-9.1-903.jdbc4.jar:
weli@power:~/projs/jboss-as-7.1.1.Final/modules/org/postgresql/main$ ls postgresql-9.1-903.jdbc4.jar
然后我们要制作module.xml,内容如下:
- <module xmlns="urn:jboss:module:1.1" name="org.postgresql">
- <!-- Load with jboss-cli command:
- /subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver,driver-class-name=org.postgresql.Driver,driver-module-name=org.postgresql)
- -->
- <resources>
- <resource-root path="postgresql-9.1-903.jdbc4.jar"/>
- </resources>
- <dependencies>
- <module name="javax.api"/>
- <module name="javax.transaction.api"/>
- </dependencies>
- </module>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql"> <!-- Load with jboss-cli command: /subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver,driver-class-name=org.postgresql.Driver,driver-module-name=org.postgresql) --> <resources> <resource-root path="postgresql-9.1-903.jdbc4.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
这样,这个module就算制作完成了:
weli@power:~/projs/jboss-as-7.1.1.Final/modules/org/postgresql/main$ ls module.xml postgresql-9.1-903.jdbc4.jar
接下来要修改AS7的配置文件,如果用standalone模式,那么就修改standalone/configuration/standalone.xml:
<datasources> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> <driver name="postgresql-driver" module="org.postgresql"> <driver-class>org.postgresql.Driver</driver-class> </driver> </drivers> </datasources>
AS7自带一个H2的module,下面的postgresql-driver是我们添加的。这样,就完成了对postgres模块的导入。其实,我们不必手工编辑standalone.xml来添加模块。可以在AS7启动后,通过命令终端来添加:
/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver,driver-module-name=org.postgresql)
如果我们要使用这个模块,可以配置datasource: