Setting up new Datasource – connection pool in JBOSS 7

If you have a new JBoss 7.x (I am using 7.1.0) installation, you would like to first create an account for admin console. It is easy

1. goto Jboss server in browser (say localhost:8080)
2. Click on admin console (It will tell you to execute add-user.bat or add-user.sh which is inside jboss/bin folder)
3. You will select option a for ManagementRealm user.
4. This is tricky, when it asks for realm, you have to type ManagementRealm (I made this mistake to type something random)
5. Now provide username and password

Go to admin console and you can see existing datasources.

Creating a new datasource would require you to add driver jar file in module folder under appropriate structure, and add a module.xml. For you help, JBoss 7 comes with a preinstalled database driver which you can see under module/com/h2database/h2/main/, here you can see jar file and module.xml. I had to create org/postgresql/main/ and add jar and module.xml.

Now go to standalone.xmlunser /jboss/standalone/configuration and look for existing database drivers

<driver name=”h2″ module=”com.h2database.h2″>
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>

You will add information for your drivers here like

<driver name=”postgresql” module=”org.postgresql”>
<xa-datasource-class>
org.postgresql.xa.PGXADataSource
</xa-datasource-class>
</driver>

Similarly you will see datasource configuration for exisitng database like

<datasources>
<datasource jndi-name=”java:jboss/datasources/ExampleDS” pool-name=”ExampleDS” enabled=”true” use-java-context=”true”>
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>

Similarly you will add information for your database.

Reference:

https://developer.jboss.org/blogs/amartin-blog/2012/02/08/how-to-set-up-a-postgresql-jdbc-driver-on-jboss-7