Suresh Online
Essential Developer Resources
  Home Java Linux Utilities Feedback  
Overview
Configuring JDBC Drivers
Writing a Startup Class
Using Log4J
Applet Signing
 

JBoss 2.4 + TOMCAT 3.2.3


Overview

The JBoss/Server is an Open Source, standards-compliant, J2EE application server implemented in 100% Pure Java, as is our full product suite. The JBoss community of over 1000 developers world wide is working to deliver the full range of J2EE tools as the premier Enterprise Java application server for the Java 2 Enterprise Edition platform. The JBoss/Server and complement of products are delivered under a public license
Refer following link for information about JBoss Application Server, features etc.

Link: http://www.jboss.org/

Here I will listing articles which I could not find given in JBoss Documentation.
For JBoss documentation, refer following link

Link: http://www.jboss.org/docs

Configuring JDBC Drivers

Here I give an overview of configuring JDBC Drivers for Microsoft SQL Server. Install a JDBC Driver
I was able to configure following JDBC Drivers for JBoss successfully.
Obtain and install the JDBC Driver which suits your requirements.
Weblogic JDriver: www.bea.com
Atinav AveConnect JDBC Driver: www.atinav.com
Merant DataDirect Connect JDBC: www.merant.com
J-netDirect JSQLConnect JDBC Driver: www.j-netdirect.com

Copy the suitable libraries or jars of the above JDBC Drivers in the "lib/ext" folder of the JBoss installation directory.

For Atinav: TaveConn24C.jar or TaveConn24M.jar
For JSQLConnect: JSQLConnect.jar
For Merant: base.jar, util.jar and sqlserver,jar
For Weblogic 5.10: mssqlserver4v65.jar
Note: For Weblogic ensure that weblogic license folder is in classpath

Modify Jboss.jcml file
If you are using TOMCAT along with JBoss, you will have to modify conf/tomcat/jboss.jcml file. For standalone server, modify conf/default/jboss.jcml file.
Add an entry for the driver to the list of drivers that JBoss loads at startup.
My Entry for the above drivers looks like the following. You may delete the unnecessary entries

<mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider">
<attribute name="Drivers">
org.hsql.jdbcDriver,org.enhydra.instantdb.jdbc.idbDriver,
net.avenir.jdbc2.Driver,
com.merant.datadirect.jdbc.sqlserver.SQLServerDriver,
com.jnetdirect.jsql.JSQLDriver,
weblogic.jdbc.mssqlserver4.Driver
</attribute>
</mbean>

At this point, you have told JBoss about your driver. You will now set up a connection pool that your EJBeans can connect to

For Atinav AveConnect JDBC Driver
<mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=SQLServerAtinav">
<attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute>
<attribute name="PoolName">SQLServerAtinav</attribute>
<attribute name="URL">jdbc:AvenirDriver://127.0.0.1:1433/master;uid=sa;pwd=sa</attribute>
</mbean>

For Merant DataDirect Connect JDBC Driver
<mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=SQLServerMerant">
<attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute>
<attribute name="PoolName">SQLServerMerant</attribute>
<attribute name="URL">jdbc:merant:sqlserver://suresh:1433</attribute>
<attribute name="Properties">DatabaseName=Master</attribute>
<attribute name="JDBCUser">sa</attribute>
<attribute name="Password">sa</attribute>
</mbean>

For JSQLConnect JDBC Driver
<mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=SQLServerJSQL">
<attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute>
<attribute name="PoolName">SQLServerJSQL</attribute>
<attribute name="URL">jdbc:JSQLConnect://localhost/database=Master&amp;user=sa&amp;password=sa</attribute>
</mbean>

For Weblogic 5.10 Jdriver
<mbean code="org.jboss.jdbc.XADataSourceLoader" name="DefaultDomain:service=XADataSource,name=SQLServerWeblogic"> <attribute name="DataSourceClass">org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl</attribute> <attribute name="PoolName">SQLServerWeblogic</attribute> <attribute name="URL">jdbc:weblogic:mssqlserver4:Master@suresh:1433?user=sa&amp;password=sa</attribute> </mbean>

Start JBoss and ensure that the JDBC driver is found and the connection pool is created

Writing a Startup Class

In this section, I will try to explain on how to write and configure a Startup class. In JBoss, the Startup class has to be written as a MBean. (JBoss uses JMX architecture extensively).
Step1: Write the Mbean interface
Note: The interface name should end with MBean.
package com.suresh.starup;
public interface SureshStartupMBean {

  //following are the service methods which needs to be implemented
  //and are called by the JBoss container
  //When server starts, first init is called and then start is called
  //write code in start to do implement any startup functionality
  public abstract void init() throws Exception;
  public abstract void start() throws Exception;

  //When server stops, first stop is called and then destroy is called
  //write code in stop to do implement any cleanup functionality
  public abstract void stop() throws Exception;
  public abstract void destroy() throws Exception;
}

Step2: Write the Startup class implementing the Mbean interface
package com.suresh.starup;
import org.jboss.util.*; //from jboss.jar
import javax.management.*; //from jmxri.jar

public class SureshStartup implements MBeanRegistration, SureshStartupMBean {

  public WorldTechStartup() {
  }
  //the ObjectName returned is important and is to be given exactly
  //in jboss.jcml file
  public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception {
    return new ObjectName(":service=SureshStartup");
  }

  public void postRegister(java.lang.Boolean registrationDone) {}
  public void preDeregister() throws java.lang.Exception { }
  public void postDeregister() {}
  public void init() throws Exception { }

  public void start() throws Exception {
    //write custom code here to do implement any startup functionality
  }
  public void stop() throws Exception {
    //write custom code here to do implement any cleanup functionality
  }
  public void destroy() throws Exception {}
  }

Step 3: Create a Jar
Create a jar file of the above two classes, say SureshStartup. Place the jar in the "lib/ext" folder.
Step 4: Make Entry in jboss.jcml
<mbean code=" com.suresh.starup.SureshStartup" name=":service=SureshStartup">
</mbean>

Start the server and ensure that the Startup class is loaded properly.

Using Latest Log4J Package with JBoss

JBoss is tightly coupled with Log4J. The only problem being it used an old version of log4J.So when we use the Log4J latest package in our source code, we get following errors java.lang.NoClassDefFoundError: org/apache/log4j/Category

The solution is to remove the "Log4Jservice" from the "jboss.conf" file and adding the log4j-full.jar manually to the classpath.