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 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″>

You will add information for your drivers here like

<driver name=”postgresql” module=”org.postgresql”>

Similarly you will see datasource configuration for exisitng database like

<datasource jndi-name=”java:jboss/datasources/ExampleDS” pool-name=”ExampleDS” enabled=”true” use-java-context=”true”>

Similarly you will add information for your database.