Download PgJDBC.
postgresql-9.1-902.jdbc4.jar, the current version at time of writing. Adjust any filenames to match if you need a different version.Now deploy the JDBC driver to JBoss AS 7 by putting it in the
deployments folder or using the deploy command in jboss-cli. This will work for most, but not all, purposes.Alternately, you an define a PostgreSQL JDBC driver module:
- Create the path
$JBOSS_HOME/modules/org/postgresql/main. Themodules/orgpart should already exist, make directories for the rest. - In
$JBOSS_HOME/modules/org/postgresql/main/modules.xmlwith the following content, changing theresource-rootentry for the PgJDBC driver to refer to the driver you wish to use.
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.1-902.jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
3.Into the same directory asmodules.xmlplacepostgresql-9.1-902.jdbc4.jar
4.Openjboss-cliby running$JBOSS_HOME/bin/jboss-cli --connect
5. Run the command:
/subsystem=datasources/jdbc-driver=postgresql-driver:add(driver-name=postgresql-driver, driver-class-name=org.postgresql.Driver, driver-module-name=org.postgresql)6.Now create any required data sources, etc, usingpostgresql-driveras the driver name.
You can create a datasource via the web ui, withjboss-cliwith thedata-source createcommand
(seedata-source --help,data-source add --help), or by deploying a-ds.xmlfile like this
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jndi-name="java:/datasources/some-ds" enabled="true" use-java-context="true"
pool-name="some-ds-pool">
<connection-url>jdbc:postgresql:dbname</connection-url>
<driver>postgresql-driver</driver>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
</datasource>
</datasources>
No comments:
Post a Comment