Showing posts with label JBoss AS. Show all posts
Showing posts with label JBoss AS. Show all posts

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

Wednesday, February 8, 2012

Running JBoss as a daemon

The advantage of running a JBoss instance as a service (or daemon) is that it will run in the background, taking advantage of the fact that the JBoss server is a non-interactive process. This way of running processes is particularly useful whenever you need to access a server through a command-line interface, deploy an application and run the server.

This procedure was done under Fedora 16 x64 and JBoss 5.1 community version.

1) Copy the file jboss_init_redhat.sh which is under $JBOSS_HOME/bin into /etc/init.d
2) You should rename it so that it represents the service you are referring to, for example jboss-dev
3) Now you should at least modify the following variables in the jboss-dev file:
#define where jboss is - this is the directory containing directories log, bin, conf etc  
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"RUNASIS"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/local/jdk/bin"}

#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"test-standard"}

4) Now you can run these commands to start, restart or stop the servers:
service jboss-dev start
service jboss-dev restart
service jboss-dev stop

Even when stopping JBoss through a service it may fail due to external events and we may not notice it. So, it is always recommended to check the logs...
tail -f /opt/jboss/server/test-standard/log/server.log
...as well as running services:
ps aux | grep java
If you see the process is still there then you should take the pid of that process (say 999), and kill the process with either one of these two commands: (keep in mind that -15 is a clean shutdown and -9 should be used in case the process still does not respond)
kill -15 999
kill -9 999