Just another WordPress site

30Jul/110

Jboss 7 + PostgreSQL 9

After installing Jboss 7 and PostgreSQL 9 you need to

  1. Create a user and a database for JBoss
  2. Install the JDBC driver in JBoss
  3. Add a datasource to your JBoss configuration

1. Postgres setup

Open the command line in your PostgreSQL directory

pg_ENV
cd bin
createuser -D -E -R -P -S jboss

Enter a new password, it will be used in your JBoss config

createdb -O jboss jboss "PostgreSQL datasource for JBoss"

2. Jdbc driver install

Go to your JBoss directory (called later <JBoss7>), then the modules folder.
Create a simple nested folders structure: org\postgresql\main

Open <JBoss7>/modules/org/postgresql/main

Download the current jdbc4 version
at the time of this post: postgresql-9.0-801.jdbc4.jar

Create a file named module.xml with following content

<?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="org.postgresql">
        <resources>
            <resource-root path="postgresql-9.0-801.jdbc4.jar"/>
        </resources>
        <dependencies><module name="javax.api"/></dependencies>
    </module>

There should be two files in the main folder now.
<JBoss7>/modules/org/postgresql/main/postgresql-9.0-801.jdbc4.jar
<JBoss7>/modules/org/postgresql/main/module.xml

3. Datasource configuration

Edit
<JBoss7>/standalone/configuration/standalone.xml

Find <datasources> and add the datasource

<datasource jndi-name="java:jboss/datasources/PostgresDS" pool-name="PostgresDS">
	<connection-url>jdbc:postgresql://localhost:5432/jboss</connection-url>
	<driver-class>org.postgresql.Driver</driver-class>
	<driver>postgresql-jdbc4</driver>
	<pool>
		<min-pool-size>2</min-pool-size>
		<max-pool-size>20</max-pool-size>
		<prefill>true</prefill>
	</pool>
	<security>
		<user-name>jboss</user-name>
		<password> password from the first step, entered after createuser </password>
	</security>
	<validation>
		<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
	</validation>
</datasource>
<drivers>
    <driver name="postgresql-jdbc4" module="org.postgresql"/>
</drivers>

in <drivers> add

<driver name="postgresql-jdbc4" module="org.postgresql"/>

4. Start Jboss

Notes:
When running JBoss in domain mode you should:
  • use the domain folder instead of standalone
  • consider installing the driver as a deployment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.