Hot questions for Using Enterprise JavaBeans in initial context


When we create a new InitialContext for remote access to Enterprise Java Beans, after work is done, should we always close the context via context.close() ?

Here is a code sample:

// Client side method
private void doSomeActionMethod() {
    RouteTransactionFacadeBeanRemote remote = null;
    final Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    Context context = null;
    try {
        context = new InitialContext(jndiProperties);
        remote = (RouteTransactionFacadeBeanRemote) context


        } catch (NamingException e) {
        } finally {
            try {
                // Should we always do this?
                if (context != null) context.close();
            } catch (NamingException ex) {


From javadocs:

Closes this context. This method releases this context's resources immediately, instead of waiting for them to be released automatically by the garbage collector. This method is idempotent: invoking it on a context that has already been closed has no effect. Invoking any other method on a closed context is not allowed, and results in undefined behaviour.

Although, garbage collector will collect them but instead of waiting for gc, you should close it by the provided function. So, my answer is, yes you should close this as well as any other resource that should be closed.


I am trying to set a new InitialContext in the following manner (which is pretty standard I believe):

private static InitialContext getInitialContext() throws NamingException {

    InitialContext context = null;

    try {
        Properties properties = new Properties();
        properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
        properties.put(Context.SECURITY_PRINCIPAL, "username");
        properties.put(Context.SECURITY_CREDENTIALS, "password");
        context = new InitialContext(properties);
        System.out.println("\n\tGot initial Context: " + context);
    catch (Exception e) {
    return context;

public static void sendMessage(RoboticsParameters object_msg) throws Exception {

    InitialContext context = getInitialContext();

    // other code

The code "fails" at the line where the new InitialContext is created using the properties and i get a java.lang.NullPointerException. I suspect I am missing an argument. Here is the stack trace:

WARN: EJB client integration will not be available due to a problem setting up the EJB client handler java.lang.NullPointerException
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.sun.naming.internal.VersionHelper12.loadClass(
at com.sun.naming.internal.VersionHelper12.loadClass(
at javax.naming.spi.NamingManager.getInitialContext(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(

Any suggestions?

I am running JBoss EAP 6.4 and using EJB 3. I have jboss-client.jar in the class path.


I checked the source code for:


and found where the log message was coming from:

public class InitialContextFactory implements javax.naming.spi.InitialContextFactory {
    // code
    private static final String REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME = "org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler";
    // code
        try {
            klass = classLoader.loadClass(REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME);
            method = klass.getMethod("setupEJBClientContext", new Class<?>[] {Properties.class, List.class});
        } catch (Throwable t) {
            logger.warn("EJB client integration will not be available due to a problem setting up the EJB client handler", t);
    // other code

The class org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler was in the jar that I added to the class path but for some reason there were problems loading the class.

Then I stumbled upon this small README-EJB-JMS.txt file in the [jboss_home]/bin/client folder which states the following:

"Maven users should not use this jar, but should use the following BOM dependencies instead


This is because using maven with a shaded jar has a very high chance of causing class version conflicts, which is why we do not publish this jar to the maven repository."

So, I added the maven dependency instead of having the jar in my class path and VOILA! It works!


This issue is very common. I have read some articles but can't find the problem. I want to create a simple HelloWorld program in EJB 3.0, eclipse luna, jboss 7.1.1 Final.

Here is my bean:

package com.tcs.HelloWorldPack;

import javax.ejb.Stateless;

 * Session Bean implementation class HelloWorld
public class HelloWorld implements HelloWorldRemote {

     * Default constructor. 
    public HelloWorld() {
        // TODO Auto-generated constructor stub


    public void displayMsg() {
        // TODO Auto-generated method stub 
        System.out.println("Hello World!!");



Here is my remote interface:

package com.tcs.HelloWorldPack;

import javax.ejb.Local;
//import javax.ejb.Remote;
import javax.ejb.Remote;

public interface HelloWorldRemote {

    void displayMsg();

Here is my client which is running in the same machine:

package com.tcs.HelloWorldClient;

import java.util.Hashtable;
import java.util.Properties;

import com.tcs.HelloWorldPack.*;

import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class HelloWorldClient {

    public static void main(String[] args) throws NamingException {

        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put(javax.naming.Context.SECURITY_PRINCIPAL, "myUser");
        jndiProperties.put(javax.naming.Context.SECURITY_CREDENTIALS, "myPass");
//        jndiProperties.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
//        jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put("jboss.naming.client.ejb.context", true);

        final Context context = new InitialContext(jndiProperties);

        final String appName= "HeloWorldEJBEAR";
        final String moduleName= "";
        final String distinctName ="";
        final String beanName = "HeloWorld";
        final String viewClassName = "com.tcs.HelloWorldPack.HelloWorldRemote";
        HelloWorldRemote hello = (HelloWorldRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);




This is my file:

remote.connection.default.port = 4447


I have put the properties file in the classpath also.But this is happening when I am trying to run it:

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:HeloWorldEJBEAR,modulename:,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@413ded77
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(
    at com.sun.proxy.$Proxy0.displayMsg(Unknown Source)
    at com.tcs.HelloWorldClient.HelloWorldClient.main(
Jan 08, 2015 3:34:44 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleEnd
INFO: Channel Channel ID de8d2aa6 (outbound) of Remoting connection 44477156 to localhost/ can no longer process messages

I have also uploaded my directory structure. I am new to the EJB concept. Please help me to find where is the problem. Thanks in advance.


Your module name is an empty String, but the module name can't be an empty string in the JNDI name. Look here

you have to set the name of your ejb module .jar, without the .jar suffix.

final String moduleName = "HeloWorldEJB";

Then it should work.