[JBoss.org AS7] Datasource configuration with Postgresql.

January 2, 2012

Dear all,

Well, recently I tried to make my application work on JBoss.org AS7.

Just to check if I should have to do some code modifications in my application when JBoss.com EAP 6 will be released.

FYI, you can download freely JBoss.org AS7 at the following URL –  http://www.jboss.org/jbossas – however as it is a community project you will not have any support with SLA.

In case of you would need one(s) then I would suggest you to subscribe to  JBoss EAP Solutions –   http://www.jboss.com/

So,  one of my main targets was to make AS7 work with Postgresql as its underlying database.

1] I wanted to use an updated Postgresql JDBC then I had to download it from the JDBC Postgresql website –  http://jdbc.postgresql.org/download.html

I used postgresql-9.1-901.jdbc4.jar

2]  I had to create dedicated directories and files inside the JBoss.org AS7 directory.


Then, to upload the postgresql-9.1-901.jdbc4.jar in the following path :   jboss-as-7.0.2.Final/modules/org/postgres/main

And then to create specific xml file named : module.xml  with the following content :

<module xmlns="urn:jboss:module:1.0" name="org.postgres">
    <resource-root path="postgresql-9.1-901.jdbc4.jar"/>
     <module name="javax.api"/>
     <module name="javax.transaction.api"/>
So in the  jboss-as-7.0.2.Final/modules/org/postgres/main path you should retrieved the following files :

> postgresql-9.1-901.jdbc4.jar – Postgresql JDBC4 driver.

> postgresql-9.1-901.jdbc4.jar.index – Index file generated by JBoss. That file should automatically created by the JBoss instance as soon as the Postgresql JDBC Driver will be discover by the instance.

> module.xml – Module Description

4] Then, I  had to add a Posgresql node in the following section of the jboss-as-7.0.2.Final/standalone/configuration/standalone.xml file.

<subsystem xmlns="urn:jboss:domain:datasources:1.0">


                  <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true" jta="true" use-java-context="true" use-ccm="true">

                  <datasource jndi-name="java:jboss/datasources/PostgresqlDS" pool-name="java:jboss/datasources/PostgresqlDS_Pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
                    <driver name="postgresql" module="org.postgres">
                    <driver name="h2" module="com.h2database.h2">
Rem: Do not forget to change the Postgresql Database user and password to yours.

5] You can check in the JBoss Administration Console your JDBC connection is rcognized – http://localhost:9990/console/App.html#server/datasources

You should see a green light if everything is OK.

6] Finally, do not forget to change the persistence -persistence.xml – file of your application to check your application works with the new Posgresql datasource.

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
<persistence-unit name="astroDatabase">
                  <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
                  <property name="hibernate.show_sql" value="false"/>
                  <property name="hibernate.format_sql" value="false"/>
                  <property name="hibernate.use_sql_comments" value="false"/>

Ref #1 : http://community.jboss.org/wiki/JBossAS7-DatasourceConfigurationForPostgresql

Ref #2 : http://community.jboss.org/thread/168958

Best Regards



2 Responses to “[JBoss.org AS7] Datasource configuration with Postgresql.”

  1. akrsmv said

    Thanks for this post! It was very useful to me for two reasons:
    – I found aggregated info on the exact problem I had which solved it
    – It led me to the though its already a time to start blogging for such things myself too.
    P.S Btw, after I create my own blog, may I reblog you on that post 🙂 ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: