Tuesday, December 4, 2012

Datasource and database driver in JBoss 7 without module definition

So, you just downloaded JBoss 7 and want to give it a try. You notice that the whole directory structure changed completely but do not want to "waste time with new administration stuff" and want to use another datasource other that the default one which comes with H2 (an in-memory database).

With this configuration, you will be able to easily create a new datasource for JBoss 7 using a new database driver with minimal configuration. This configuration has been tested only in standalone mode and may not be suitable for cluster/production environments. Note that this way will only work with JDBC4 drivers.

Just deploy your jar under <JBOSS_HOME>\standalone\deployments and add the following datasource definition to your <JBOSS_HOME>\standalone\configuration\standalone.xml

<datasource jndi-name="java:jboss/datasources/PostgreSQLDS" pool-name="PostgreSQLDS" enabled="true" use-java-context="true">
       <connection-url>jdbc:postgresql://<your_ip>:<your_db_port>/<your_db></connection-url>
       <driver>postgresql-9.1-901.jdbc4.jar</driver>
      <security>
            <user-name>postgres</user-name>
            <password>123456</password>
      </security>
</datasource>

Now just run <JBOSS_HOME>/bin/standalone.sh (if you are using Linux/Mac, .bat if Windows) to start the server. You can check the datasource health in the new administration console.

Additional information on deploying datasources to JBoss 7 can be found here

1 comment: