How to create a simple EJB3 project in Eclipse (JBoss 7.1)

7 February 2012 By Nithya Vasudevan 105,437 views 121 Comments
44 Flares Twitter 6 Facebook 22 Google+ 16 44 Flares ×

Environment Used

  • JDK 6 (Java SE 6)
  • EJB 3.0 (stateless session bean)
  • Eclipse Indigo IDE for Java EE Developers (3.7.1)
  • JBoss Tools – Core 3.3.0 M5 for Eclipse Indigo (3.7.1)
  • JBoss Application Server (AS) 7.1.0.CR1b / Final

Setting up development environment:
Read this page for installing and setting up the environment for developing and deploying EJB 3.0 Session bean on JBoss application server.

Project Description:

  • We are going to create a simple EJB 3 HelloWorld stateless session bean project and a remote Java application client which will call/invoke the bean.
  • This “HelloWorld” example explains how to develop, deploy and run EJB3 Session Bean (stateless and stateful) in JBoss application server.
  • For testing this “HelloWorld” example we write a remote Java Application Client (main() method).
  • For simplicity, the session bean and the client to access the session bean are created in the same project.

Creating New EJB Project

  • Open Eclipse IDE and create a new EJB project which can be done in three ways,
    • Right click on Project Explorer -> New -> EJB Project
    • File menu -> New -> EJB Project
    • Click on the down arrow on New icon on toolbar -> EJB Project

  • Enter the project name as “HelloWorldSessionBean” and make sure the JBoss 7.1 Runtime has been selected with the EJB 3.0 Module version.

  • Click Next -> Next -> and Finish.
  • You will see an EJB project in the Project Explorer view.

Creating Session Bean and Bean Interface

  • Right click on ejbModule -> New -> Session Bean (EJB 3.x)

  • Enter the Java package name as com.ibytecode.businesslogic
  • Enter the Class name as HelloWorldBean
  • Select the State type as Stateless
  • Check the Remote Business Interface and enter the name as com.ibytecode.business.HelloWorld. The business interface will be created in different package (com.ibytecode.business)
  • Click Finish

Coding Bean and the Interface

  • Open Bean Interface and type the following code and save the file (Ctrl+s).
  • Interface can be either @Remote or @Local. In this example we have used @Remote.
package com.ibytecode.business;
import javax.ejb.Remote;

@Remote
public interface HelloWorld {
	public String sayHello();
}

  • Open Bean and type the following code and save the file.
  • Bean type can either be @Stateful or @Stateless. In this example we have used @Stateless.
package com.ibytecode.businesslogic;

import com.ibytecode.business.HelloWorld;
import javax.ejb.Stateless;

@Stateless
public class HelloWorldBean implements HelloWorld {
    public HelloWorldBean() {
    }

	public String sayHello() {
		return "Hello World !!!";
	}
}

Now the Stateless Session Bean has been created. The next step is to deploy the bean on the server.

Deploying EJB project

  • Now we need to deploy the stateless session bean “HelloWorldBean” on server.
  • Deploying the project can be done in two ways,
    • Right click on the EJB project -> Run As -> Run On Server. Select the existing “JBoss 7.1 Runtime Server” and click Finish.
    • Right click on “JBoss 7.1 Runtime Server” available in Servers view -> Add and Remove… -> Select the EJB JAR file from the left pane and click Add-> and then Finish.

Start/Restart the Server

Right click on “JBoss 7.1 Runtime Server” from Servers view and click on Start if it has not yet been started.
If the project is deployed properly with global JNDI mapping then you will see the following message in the console.

Creating Client

  • The next step is to write a remote Java client application (with main()) for accessing and invoking the EJBs deployed on the server
  • Client uses JNDI to lookup for a proxy of your bean and invokes method on that proxy.

Creating JNDI InitialContext

Obtaining a Context using InitialContext

  • All naming service operations are performed on some implementation of the javax.naming.Context interface. Therefore, the starting point of interacting with the naming service is to obtain a Context by providing the properties specific to the server implementation being used. In our case it is, JBoss Application Server.
  • To create a javax.naming.InitialContext, we need to initialize it with properties from the environment. JNDI verifies each property’s value by merging the values from the following two sources,
    • Using parameterized constructor of InitialContext which takes properties of supplied environment
    • jndi.properties resource files found on the classpath.

NOTE:We will use parameterized constructor for initializing the InitialContext.

For JBoss AS 7 we need to set the Context.URL_PKG_PREFIXES property with value “org.jboss.ejb.client.naming” to obtain the InitialContext.

The following utility class is used to create InitialContext for JBoss AS and can be reused in all applications. Otherwise the code written in this class should be repeated in all clients.

  • Right click on ejbModule -> New -> Class
  • Enter the package name as com.ibytecode.clientutility
  • Enter the Class name as ClientUtility
  • Click on Finish

package com.ibytecode.clientutility;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ClientUtility {

	private static Context initialContext;

	private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";

	public static Context getInitialContext() throws NamingException {
		if (initialContext == null) {
			Properties properties = new Properties();
			properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);

			initialContext = new InitialContext(properties);
		}
		return initialContext;
	}
}

Creating client class

  • Right click on ejbModule -> New -> Class
  • Enter the package name as com.ibytecode.client
  • Enter the Class name as EJBApplicationClient
  • Check the main() method option
  • Click on Finish

package com.ibytecode.client;

import javax.naming.Context;
import javax.naming.NamingException;

import com.ibytecode.business.HelloWorld;
import com.ibytecode.businesslogic.HelloWorldBean;
import com.ibytecode.clientutility.ClientUtility;

public class EJBApplicationClient {
	
	public static void main(String[] args) {
		HelloWorld bean = doLookup();
		System.out.println(bean.sayHello()); // 4. Call business logic
	}

	private static HelloWorld doLookup() {
		Context context = null;
		HelloWorld bean = null;
		try {
			// 1. Obtaining Context
			context = ClientUtility.getInitialContext();
			// 2. Generate JNDI Lookup name
			String lookupName = getLookupName();
			// 3. Lookup and cast
			bean = (HelloWorld) context.lookup(lookupName);

		} catch (NamingException e) {
			e.printStackTrace();
		}
		return bean;
	}

	private static String getLookupName() {
/* 
The app name is the EAR name of the deployed EJB without .ear suffix. 
Since we haven't deployed the application as a .ear, 
the app name for us will be an empty string
*/
		String appName = "";

		/* The module name is the JAR name of the deployed EJB 
        without the .jar suffix.
		*/
		String moduleName = "HelloWorldSessionBean";

/*AS7 allows each deployment to have an (optional) distinct name. 
This can be an empty string if distinct name is not specified.
*/
		String distinctName = "";

		// The EJB bean implementation class name
		String beanName = HelloWorldBean.class.getSimpleName();

		// Fully qualified remote interface name
		final String interfaceName = HelloWorld.class.getName();

		// Create a look up string name
		String name = "ejb:" + appName + "/" + moduleName + "/" + 
			distinctName 	+ "/" + beanName + "!" + interfaceName;

		return name;
	}
}

Setting up EJB client context properties

An EJB client context is a context which contains contextual information for carrying out remote invocations on EJBs. This is a JBoss AS specific API. The EJB client context can be associated with multiple EJB receivers. Each EJB receiver is capable of handling invocations on different EJBs.
For example, an EJB receiver “ClientA” might be able to handle invocation on a bean identified by app-A/module-A/distinctinctName-A/BeanA!com.ibc.RemoteBeanA, app-B/module-B/distinctName-B/BeanB!RemoteBeanB, etc. Each such EJB receiver knows about what set of EJBs it can handle and each of the EJB receiver knows which server target to use for handling the invocations on the bean. The server IP address and its remoting port should be specified in the properties file placed in the client classpath. This properties file (EJB client context) will then be used internally by the JNDI implementation to handle invocations on the bean proxy.

Create a file “jboss-ejb-client.properties” in the classpath of the application. We can place it in ejbModule folder of our application. The jboss-ejb-client.properties contains the following properties:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

Adding JAR files required for the client to run the client application

  • Open Run Configurations… in Run menu or Run Configurations in Run icon

  • Select the client application (EJBApplicationClient) under Java Application from left pane and open the Classpath tab from right side pane. If you don’t see your client application, run it once. Select “User Entries” and click on “Add External JARs”

  • Add the following JAR files.
    JAR nameLocation
    jboss-transaction-api_1.1_spec-1.0.0.Final.jarAS7_HOME/modules/javax/transaction/api/main/
    jboss-ejb-api_3.1_spec-1.0.1.Final.jarAS7_HOME/modules/javax/ejb/api/main/
    jboss-ejb-client-1.0.0.Beta10.jarAS7_HOME/modules/org/jboss/ejb-client/main/
    jboss-marshalling-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/main/
    xnio-api-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/main/
    jboss-remoting-3.2.0.CR6.jarAS7_HOME/modules/org/jboss/remoting3/main/
    jboss-logging-3.1.0.Beta3.jarAS7_HOME/modules/org/jboss/logging/main/
    xnio-nio-3.0.0.CR5.jarAS7_HOME/modules/org/jboss/xnio/nio/main/
    jboss-sasl-1.0.0.Beta9.jarAS7_HOME/modules/org/jboss/sasl/main/
    jboss-marshalling-river-1.3.0.GA.jarAS7_HOME/modules/org/jboss/marshalling/river/main/

    You can also add it in Build path (Right click on your EJB Project->Properties, select Java Build Path from left side pane and select Libraries from right side and click on Add External JARs)

If you are using JBoss Application Server (AS) 7.1.0 Final version then it is sufficient to add only one client JAR file (jboss-client-7.1.0.Final.jar) which is located in AS7_HOME/bin/client

The figure below shows the final directory structure of this example.

Run the client

Use Ctrl + F11 to run the client.

Hello World !!!

Tags: , , , ,

  • http://www.opencsta.org Chris Mylonas

    That is very cool!

    I think the more valuable part of the tutorial is actually accessing the EJB from a standalone application and showing which jars are required in your standalone app’s classpath for jboss 7.1 – seeing as it’s still in beta and jboss 7 is still rather new.

    Would you be able to create a tutorial that creates a similar standalone client but using maven?

    Great work,
    Cheers

  • http://theopentutorials.com nithya

    Thanks. I will try to do the same with Maven and Eclipse.

  • iqbal

    I have try your code, just create interface and session bean class, but it produce error:

    15:44:08,633 INFO [org.jboss.modules] JBoss Modules version 1.1.0.CR6
    15:44:08,856 INFO [org.jboss.msc] JBoss MSC version 1.0.1.GA
    15:44:08,898 INFO [org.jboss.as] JBoss AS 7.1.0.CR1b “Flux Capacitor” starting
    15:44:09,576 INFO [org.jboss.as] Creating http management service using socket-binding (management-http)
    15:44:09,576 INFO [org.xnio] XNIO Version 3.0.0.CR7
    15:44:09,583 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.0.CR7
    15:44:09,590 INFO [org.jboss.remoting] JBoss Remoting version 3.2.0.CR8
    15:44:09,602 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
    15:44:09,636 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool — 26) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
    15:44:09,639 INFO [org.jboss.as.clustering] (ServerService Thread Pool — 30) JBAS010300: Activating Infinispan subsystem.
    15:44:09,652 INFO [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.6.Final)
    15:44:09,674 INFO [org.jboss.as.osgi] (ServerService Thread Pool — 39) JBAS011910: Activating OSGi Subsystem
    15:44:09,688 INFO [org.jboss.as.security] (ServerService Thread Pool — 44) Activating Security Subsystem
    15:44:09,693 INFO [org.jboss.as.naming] (ServerService Thread Pool — 38) JBAS011800: Activating Naming Subsystem
    15:44:09,697 INFO [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service
    15:44:09,699 INFO [org.jboss.as.jaxr] (MSC service thread 1-5) Binding JAXR ConnectionFactory: java:jboss/jaxr/ConnectionFactory
    15:44:09,708 INFO [org.jboss.as.mail.extension] (MSC service thread 1-3) JBAS015400: Bound mail session
    15:44:09,721 INFO [org.jboss.as.webservices] (ServerService Thread Pool — 48) JBAS015537: Activating WebServices Extension
    15:44:09,757 INFO [org.jboss.as.security] (MSC service thread 1-4) Picketbox version=4.0.6.Beta2
    15:44:09,861 INFO [org.jboss.as.remoting] (MSC service thread 1-1) Listening on /127.0.0.1:4447
    15:44:09,868 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-2) JBoss Web Services – Stack CXF Server 4.0.0.GA
    15:44:10,062 INFO [org.apache.tomcat.util.net.AprEndpoint] (MSC service thread 1-7) Failed to create poller with specified size of 32768
    15:44:10,068 INFO [org.apache.tomcat.util.net.AprEndpoint] (MSC service thread 1-7) Failed to create poller with specified size of 32768
    15:44:10,074 INFO [org.apache.tomcat.util.net.AprEndpoint] (MSC service thread 1-7) Failed to create poller with specified size of 16384
    15:44:10,075 INFO [org.apache.coyote.http11.Http11AprProtocol] (MSC service thread 1-7) Starting Coyote HTTP/1.1 on http–127.0.0.1-8080
    15:44:10,214 INFO [org.jboss.as.remoting] (MSC service thread 1-2) Listening on /127.0.0.1:9999
    15:44:10,215 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source
    15:44:10,221 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) JBAS015012: Started FileSystemDeploymentService for directory /Users/mi/jboss-as-7.1.0.CR1b/standalone/deployments
    15:44:10,224 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads – 1) JBAS015003: Found HelloWorld.jar in deployment directory. To trigger deployment create a file called HelloWorld.jar.dodeploy
    15:44:10,277 INFO [org.jboss.as] (Controller Boot Thread) JBoss AS 7.1.0.CR1b “Flux Capacitor” started in 1900ms – Started 130 of 200 services (68 services are passive or on-demand)
    15:44:10,286 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) Starting deployment of “HelloWorld.jar”
    15:44:10,400 WARN [org.jboss.modules] (MSC service thread 1-2) Failed to define class com.ibytecode.businesslogic.HelloWorldBean in Module “deployment.HelloWorld.jar:main” from Service Module Loader: java.lang.UnsupportedClassVersionError: com/ibytecode/businesslogic/HelloWorldBean : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method) [:1.6.0_29]
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) [:1.6.0_29]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [:1.6.0_29]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) [:1.6.0_29]
    at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:391) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:243) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:73) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.Module.loadModuleClass(Module.java:505) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:182) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.0.CR6]
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:111)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:54)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_29]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_29]
    at java.lang.Thread.run(Thread.java:680) [:1.6.0_29]

    15:44:10,417 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit.”HelloWorld.jar”.POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit.”HelloWorld.jar”.POST_MODULE: Failed to process phase POST_MODULE of deployment “HelloWorld.jar”
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_29]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_29]
    at java.lang.Thread.run(Thread.java:680) [:1.6.0_29]
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011093: Could not load component class com.ibytecode.businesslogic.HelloWorldBean
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:113)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:54)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) [jboss-as-server-7.1.0.CR1b.jar:7.1.0.CR1b]
    … 5 more
    Caused by: java.lang.ClassNotFoundException: com.ibytecode.businesslogic.HelloWorldBean from [Module "deployment.HelloWorld.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:111)
    … 7 more

    15:44:10,424 INFO [org.jboss.as.server] (DeploymentScanner-threads – 2) JBAS015856: Undeploy of deployment “HelloWorld.jar” was rolled back with failure message {“JBAS014671: Failed services” => {“jboss.deployment.unit.\”HelloWorld.jar\”.POST_MODULE” => “org.jboss.msc.service.StartException in service jboss.deployment.unit.\”HelloWorld.jar\”.POST_MODULE: Failed to process phase POST_MODULE of deployment \”HelloWorld.jar\”"}}
    15:44:10,425 INFO [org.jboss.as.controller] (DeploymentScanner-threads – 2) JBAS014774: Service status report
    JBAS014777: Services which failed to start: service jboss.deployment.unit.”HelloWorld.jar”.POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit.”HelloWorld.jar”.POST_MODULE: Failed to process phase POST_MODULE of deployment “HelloWorld.jar”

    15:44:10,426 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads – 1) {“JBAS014653: Composite operation failed and was rolled back. Steps that failed:” => {“Operation step-2″ => {“JBAS014671: Failed services” => {“jboss.deployment.unit.\”HelloWorld.jar\”.POST_MODULE” => “org.jboss.msc.service.StartException in service jboss.deployment.unit.\”HelloWorld.jar\”.POST_MODULE: Failed to process phase POST_MODULE of deployment \”HelloWorld.jar\”"}}}}
    15:44:10,433 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) Stopped deployment HelloWorld.jar in 5ms

    Please Help..

    • Ingoom

      Good to just have a few lines of stacktrace and the rest in an attached file.

      -i

  • http://theopentutorials.com nithya

    Hi,
    This error java.lang.UnsupportedClassVersionError: com/ibytecode/businesslogic/HelloWorldBean : Unsupported major.minor version 51.0 is due to JDK version mismatch.

    To solve this problem, right click on your EJB project -> Properties -> Project Facets and change the Java version to 1.6 from drop down menu. Click on Apply and then run your project.

  • iqbal

    Hi, nithya

    Thank you for your help, its working. but when i run java application i get an exception:

    lookupName ejb:/HelloWorld//HelloWorldBean!com.ibytecode.business.HelloWorld
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.ibytecode.client.EJBApplicationClient.doLookUp(EJBApplicationClient.java:27)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:74)

    and this is the propertie file content:
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

    remote.connections=default

    remote.connection.default.host=localhost
    remote.connection.default.port = 8080
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

    How to fix this?

    Thank you

    Update:
    I am really sorry, that is my mistake, i am not put the properties in InitialContext() constructor . now that error is solve but another problem show here is the error:

    Feb 28, 2012 10:59:09 AM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.0.Beta11
    Feb 28, 2012 10:59:09 AM org.xnio.Xnio

    INFO: XNIO Version 3.0.0.CR7
    Feb 28, 2012 10:59:09 AM org.xnio.nio.NioXnio

    INFO: XNIO NIO Implementation Version 3.0.0.CR7
    Feb 28, 2012 10:59:09 AM org.jboss.remoting3.EndpointImpl

    INFO: JBoss Remoting version 3.2.0.CR8
    Feb 28, 2012 10:59:14 AM org.jboss.ejb.client.ConfigBasedEJBClientContextSelector createConnections
    ERROR: Could not create connection for connection named default
    java.lang.RuntimeException: Operation failed with status WAITING
    at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.createConnection(ConfigBasedEJBClientContextSelector.java:292)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.createConnections(ConfigBasedEJBClientContextSelector.java:209)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:138)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:120)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:110)
    at org.jboss.ejb.client.EJBClientContext.
    (EJBClientContext.java:57)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:91)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:83)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:77)
    Feb 28, 2012 10:59:14 AM org.jboss.ejb.client.ConfigBasedEJBClientContextSelector createConnections
    INFO: Connection default will not be available in EJB client context org.jboss.ejb.client.EJBClientContext@a210b5b
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:344)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:92)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:83)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:77)

    in properties file i set the remote.connections=default but it produce error “Could not create connection for connection named default”. What is the value for remote.connections?

    Thank You

  • http://theopentutorials.com nithya

    In the jboss-ejb-client.properties file change the remote.connection.default.port number from 8080 to 4447 and run the client.

  • iqbal

    Hi nithya,

    I already set to 4447, but my question why i have to change the port to 4447 because my default port is 8080?, and i have run the client but javax.ejb.NoSuchEJBException, No such EJB.

    Feb 28, 2012 4:43:23 PM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.0.Beta11
    Feb 28, 2012 4:43:23 PM org.xnio.Xnio
    INFO: XNIO Version 3.0.0.CR7
    Feb 28, 2012 4:43:23 PM org.xnio.nio.NioXnio
    INFO: XNIO NIO Implementation Version 3.0.0.CR7
    Feb 28, 2012 4:43:23 PM org.jboss.remoting3.EndpointImpl
    INFO: JBoss Remoting version 3.2.0.CR8
    Feb 28, 2012 4:43:23 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
    INFO: Received server version 1 and marshalling strategies [river]
    Feb 28, 2012 4:43:23 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
    INFO: Successful version handshake completed for receiver context org.jboss.ejb.client.EJBReceiverContext@709446e4 on channel Channel ID 92da92aa (outbound) of Remoting connection 69e328e0 to localhost/127.0.0.1:4447
    Exception in thread “main” javax.ejb.NoSuchEJBException: No such EJB[appname=, modulename=HelloWorldSessionBean, distinctname=, beanname=HelloWorldBean, viewclassname=null]
    at org.jboss.ejb.client.remoting.GeneralInvocationFailureResponseHandler.processMessage(GeneralInvocationFailureResponseHandler.java:75)
    at org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver.handleMessage(ChannelAssociation.java:297)
    at org.jboss.remoting3.remote.RemoteConnectionChannel$5.run(RemoteConnectionChannel.java:409)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

  • iqbal

    Its workiing now… thank you very much nithya

    • singh

      am getting the same error as you got ,no such ejb :( ,how did u solve
      pls let me know

      • http://theopentutorials.com Praveen Macherla

        Check ejb deployment errors, lookup string.

  • iqbal

    Nithya, i am still curious why i must change the port to 4447? why not use 8080?

    • Andrea

      The port 8080 is the http port with ejb you have to call with remote port and jboss 7 remote port for call ejb is 4447

  • http://theopentutorials.com nithya

    From JBoss AS 7.1 documentation,
    “By default AS7 uses 4447 as the remoting port. The EJB client API uses the remoting port for communicating with the server for remote invocations, so that’s the port we use in our client programs.”

  • Kumar

    File Name –> jboss-ejb-client.properties
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=localhost
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

    package com.ibytecode.clientutility;

    import java.util.Properties;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;

    public class ClientUtility {
    private static Context initialContext;
    private static final String PKG_INTERFACES = “org.jboss.ejb.client.naming”;
    public static Context getInitialContext() throws NamingException {
    if (initialContext == null) {
    Properties properties = new Properties();
    properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
    initialContext = new InitialContext(properties);
    }
    return initialContext;
    }
    }

    I AM GETTING FOLLOWING ERROR, PLEASE GUIDE ME WHERE I AM DOING MISTAKES

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.ibytecode.client.EJBApplicationClient.doLookup(EJBApplicationClient.java:26)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:13)
    Exception in thread “main” java.lang.NullPointerException
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:14)

    • http://theopentutorials.com Praveen

      Make sure you have included all the required jar files. If you use JBoss 7.1 FINAL, you need only one jar file (jboss-client-7.1.0.Final.jar which is located in ‘AS7_HOME/bin/client’ folder) in your client classpath. If you use the version mentioned in this tutorial, then include all the jars specified and run the client.

      Also make sure you have client properties file in classpath or place it in the mentioned folder in this tutorial.

  • Help

    Can anyone help me with this ??

    2012-03-23 11:24:44 org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.5.Final
    Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@9506dc4
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.sayHello(Unknown Source)

  • Help

    now i’m getting this


    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.ibytecode.client.Client.doLookup(Client.java:26)
    at com.ibytecode.client.Client.main(Client.java:13)

    • http://theopentutorials.com Praveen

      Pls see my previous comment on adding the reqd. jar files.

  • Help

    Dear Praveen,
    thx for your help, now i’m getting this… Please help me :)
    Name from getLookupName =ejb:/hw//HelloWorldBean!com.ibytecode.business.HelloWorld

    17:27:33,435 INFO [client] JBoss EJB Client version 1.0.5.Final
    Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:hw,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@d8d9850

    • http://theopentutorials.com Praveen

      Is your project name ‘hw’? If not, change ‘hw’ to your project name. Also make sure the project is deployed on the server.

  • amit

    Hi Please help me out with this exception:

    my lookup string is : “ejb:/HelloWorldSessionBean//HelloWorldBean!com.ibytecode.business.HelloWorld”

    and the stack trace is :

    Apr 03, 2012 1:35:21 AM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.2.Final
    Apr 03, 2012 1:35:34 AM org.xnio.Xnio
    INFO: XNIO Version 3.0.3.GA
    Apr 03, 2012 1:35:34 AM org.xnio.nio.NioXnio
    INFO: XNIO NIO Implementation Version 3.0.3.GA
    Apr 03, 2012 1:35:34 AM org.jboss.remoting3.EndpointImpl
    INFO: JBoss Remoting version 3.2.2.GA
    Apr 03, 2012 1:35:40 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
    WARN: Could not register a EJB receiver for connection to remote://127.0.0.1:4447
    java.lang.RuntimeException: Operation failed with status WAITING
    at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:115)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:77)
    at org.jboss.ejb.client.EJBClientContext.(EJBClientContext.java:76)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:13)

  • amit

    my jboss-ejb-client.properties file has :

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=x1
    remote.connection.x1.host=127.0.0.1
    remote.connection.x1.port=4447
    remote.connection.x1.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

    • http://theopentutorials.com Praveen

      Check Jboss server is running or not. Make sure the url 127.0.0.1:8080 displays jboss page in browser. Or else try localhost instead of 127.0.0.1 in client properties file.

  • amit

    the server is up and running.
    Tried with both localhost and 127.0.0.1 but still the error is same!

  • amit

    logs from server console after deploying the ejb application

    11:39:21,300 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) Starting deployment of “HelloWorldSessionBean.jar”
    11:39:21,800 INFO [org.jboss.as.jpa] (MSC service thread 1-2) added javax.persistence.api dependency to HelloWorldSessionBean.jar
    11:39:22,269 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named HelloWorldBean in deployment unit deployment “HelloWorldSessionBean.jar” are as follows:

    java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:global/HelloWorldSessionBean/HelloWorldBean
    java:app/HelloWorldSessionBean/HelloWorldBean
    java:module/HelloWorldBean

    11:39:23,112 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads – 1) Deployed “HelloWorldSessionBean.jar”

    • http://theopentutorials.com Praveen

      Start Jboss server and in cmd, type
      telnet 127.0.0.1 4447
      Check the port is running or not. Otherwise I don’t see any errors.

  • Fim

    Excellent tutorial

  • http://kolemik.ya.ru Gloomy

    Thanks!!! I’m just omit a step with “classpath entry” and spend a time getting “IllegalStateException: No EJB receiver available for handling”… :(

  • VAMSI KRISHNA P

    Hi,

    Thanks for such a useful explanation.

    I have developed and deployed ejb as explained. I am getting below error while running client. Could you please help me?

    Apr 10, 2012 10:12:34 PM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.5.Final
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@632d3205
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.sayHello(Unknown Source)
    at com.vamsi.client.EJBApplicationClient.main(EJBApplicationClient.java:13)

    • http://theopentutorials.com Praveen

      Vamsi,
      For “No EJB receiver available for handling” error messages, there could be one of the below problems,

      • EJB not deployed properly
      • No ejb client jar file in classpath
      • Incorrect Lookup name
      • Client properties file not in classpath

      So go through those issues and try again.

  • Lance Goforth

    I appreciate the tutorials – but I’m also getting the No EJB receiver available message – I’ve re-verified the client jars are in my classpath and the jboss-ejb-client.properties is also.

    I think one main difference is my jboss instance isn’t on local host. I’ve tried starting it with the bind properties, and I’ve tried making sure the interface is set to the correct IP – but I’m still getting no receivers available. Is there a way to enable the trace or logging for the context lookup on the server side to verify it’s actually hitting the server or not. I’m kind of at a loss right now what to check next.

    I’m in the middle of re-writing an old EJB2 app to EJB3 and trying to get the newer versions of JBoss up is a challenge in itself. In a production environment we use to pass the server IP in the client as a property, having to put it in a properties file won’t be an ideal option – I’d rather continue setting the property if possible.

    • http://theopentutorials.com nithya

      Lance,
      I have added an EJB client code without using jboss-ejb-client.properties file. Go through the link given below and let me know whether it solves your problem.
      http://pastebin.com/d2ZtdQrk

  • VAMSI KRISHNA P

    Excellent!!! it worked for me. Got the clear picture and understanding on Session Bean.

    Thanks Nithya.

  • Lance Goforth

    At first I thought no, same error. But I figured out the lookup method did work – I put in a sysout after and printed the bean and it states it is a proxy for the correct server interface so that all looks correct.

    However, I’m now getting the same “No EJB receiver available for handling” on the first method call for that object.

    As you can probably tell – I’m not doing exactly the hello world – I have an application that was working on Jboss 5.1 and 6.1 that I’m trying to move over to 7.1.

  • Lance Goforth

    Finally found the issue. It’s relating to this setup bit in the standalone.xml

    I removed the security-realm attribute and it’s working now.

    Found it here JBoss Community Groups

    I’m not sure what the issue is, but at least I can move forward now.

    Thanks for your help.

  • Pasqualino

    Hi, would you care to explain where to put the persistence.xml and how to refer to the persistence unit name when using the ejb project facet?
    Up to now, I did use the plain Java Project facet, put a META-INF folder in its root, and the persistence.xml (let’s pretend “Foo” is the unit name) there. When I use the ejb3 facet instead, a ejb-Module folder is created – and I put the persistence.xml there. When I deploy the application, I see that unit name is ejb-Module#Foo, and I don’t know how to refer to it from any Session Bean that refers to it (using ejbModule#Foo doesn’t work).

    Thanks!

    • http://theopentutorials.com Nithya

      When you create an EJB project in Eclipse, META-INF folder will automatically be created and place the persistence.xml there and not in ejbModule.
      Refer this page for detailed explanation of how to develop, deploy and run EJB3 JPA project in JBoss 7.1

  • pradeep

    hello
    ejb:/simp//HelloWorldBean!com.ibytecode.business.HelloWorld
    Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;
    at org.jboss.ejb.client.Logs.(Logs.java:44)
    at org.jboss.ejb.client.EJBClient.(EJBClient.java:40)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.doCreateProxy(EjbNamingContext.java:139)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.createEjbProxy(EjbNamingContext.java:113)
    at org.jboss.ejb.client.naming.ejb.EjbNamingContext.lookup(EjbNamingContext.java:96)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.ibytecode.client.Ejbapplicationclient.doLookUp(Ejbapplicationclient.java:37)
    at com.ibytecode.client.Ejbapplicationclient.main(Ejbapplicationclient.java:21)

    • http://theopentutorials.com Nithya

      What version of JBoss are you using? It looks like an incorrect version of JBoss Logging jar is on your client classpath.

      If you are using JBoss 7.1.0 Final version then remove all the JAR files (mentioned in the table) from your classpath and add only one client JAR file (jboss-client-7.1.0.Final.jar) which is located in AS7_HOME/bin/client.

  • csaba toth

    excellent work. thanks

  • Dan

    OK so I have 2 questions…
    1. Where does the JNDILookupClass come from?
    2. I am using JBoss 7.0.0 Final, because i can’t get the one that you use here to start…(gives the Server failed to start error) …SO i can’t find any jboss-ejb-client-1.0.0.Beta10.jar in it to add( there is no AS7_HOME/modules/org/jboss/ejb-client/main/)
    :(

    Any ideas?

    • http://theopentutorials.com Nithya Vasudevan

      JNDILookupClass was renamed to ClientUtility. I updated the screenshots to reflect the same. For your other question, use the latest version of JBoss AS 7.1.1 which is full java ee 6 compliant.

  • Pingback: JavaPins

  • http://www.vikassingh.in VIKAS SINGH

    Hi i need ur help pls give me any suggestion how can implement jboss in eclipse

  • Kunal

    Hello Nithya,

    I tried to setup your tutorial and its working fine in my machine.
    Now I am trying to now add an external JAR(gemfire.jar) file in the EJB and use that JAR in the HelloWorldBean. When I do so, and try to run the appropriate method in the HelloWorldBean, I get the following exception.

    INFO: Discarding result for invocation id 1 since no waiting context found
    Exception in thread “main” javax.ejb.EJBException: Unexpected Error
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:163)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropogatingInterceptor.processInvocation(EJBRemoteTransactionPropogatingInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
    at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:300)
    at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$200(MethodInvocationMessageHandler.java:64)
    at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:194)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)
    Caused by: java.lang.NoClassDefFoundError: com/gemstone/gemfire/cache/client/ClientCacheFactory
    at com.ibytecode.businesslogic.HelloWorldBean.insertDataIntoCache(HelloWorldBean.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
    … 25 more
    Caused by: java.lang.ClassNotFoundException: com.gemstone.gemfire.cache.client.ClientCacheFactory from [Module "deployment.HelloWorldSessionBean.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
    … 45 more

    Could you help me with this please?
    Thanks
    Kunal

    • http://theopentutorials.com Nithya Vasudevan

      You have not added your JAR file (gemfire.jar) properly in your classpath. It is throwing ClassNotFoundException.

  • Raj kumar

    Hi nithya,

    This is raj kumar. I am a EJB Fresher. I saw your website and try it your coding. But i have some problem. That is follows.,

    Aug 10, 2012 2:24:48 PM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.0.Beta10
    Aug 10, 2012 2:24:49 PM org.xnio.Xnio
    INFO: XNIO Version 3.0.0.CR5
    Aug 10, 2012 2:24:49 PM org.xnio.nio.NioXnio
    INFO: XNIO NIO Implementation Version 3.0.0.CR5
    Aug 10, 2012 2:24:49 PM org.jboss.remoting3.EndpointImpl
    INFO: JBoss Remoting version 3.2.0.CR6
    Aug 10, 2012 2:24:50 PM org.jboss.remoting3.remote.RemoteConnection handleException
    ERROR: JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
    Aug 10, 2012 2:24:50 PM org.jboss.ejb.client.ConfigBasedEJBClientContextSelector createConnections
    ERROR: Could not create connection for connection named default
    java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
    at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:91)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.createConnection(ConfigBasedEJBClientContextSelector.java:292)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.createConnections(ConfigBasedEJBClientContextSelector.java:209)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:138)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:120)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:110)
    at org.jboss.ejb.client.EJBClientContext.(EJBClientContext.java:57)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:91)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:83)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:14)
    Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
    at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:356)
    at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:205)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
    at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:179)
    at org.xnio.channels.TranslatingSuspendableChannel$2.handleEvent(TranslatingSuspendableChannel.java:100)
    at org.xnio.channels.TranslatingSuspendableChannel$2.handleEvent(TranslatingSuspendableChannel.java:98)
    at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
    at org.xnio.nio.NioHandle.run(NioHandle.java:90)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:184)
    at …asynchronous invocation…(Unknown Source)
    at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:263)
    at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:246)
    at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:353)
    at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:337)
    at org.jboss.ejb.client.ConfigBasedEJBClientContextSelector.createConnection(ConfigBasedEJBClientContextSelector.java:290)
    … 9 more
    Aug 10, 2012 2:24:50 PM org.jboss.ejb.client.ConfigBasedEJBClientContextSelector createConnections
    INFO: Connection default will not be available in EJB client context org.jboss.ejb.client.EJBClientContext@166a22b
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:344)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:92)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:83)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:14)

    • Uttam

      Hi Raj
      I am getting the same error. Did you get any resolution.

      Thanks,
      Uttam

  • Seetesh

    Hello,

    I am getting this Exception while running the client on JBoss 5.1.0 GA

    Is it mandated to use JBoss 7?

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

    Rgds,

    Seetesh

  • Karlo

    Great tutorial. Thanks for sharing

  • Owais

    Hello Praveen,
    I already add properties file and jboss-client file into refernced libraries but i still getting this error.

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:27)

    Please help me to remove this error

    • leyson castaño

      hola

      yo tengo ese mismo problema por favor ayúdame a resolverlo

      gracias

  • Sahitya

    Hi,

    Need Help. I am using Jboss 7.1 and eclipse . I followed all the steps in the tutorial. When i try to run the client, i am getting the below exception

    Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.remoting3.Remoting.createEndpoint(Ljava/lang/String;Lorg/xnio/OptionMap;)Lorg/jboss/remoting3/Endpoint;
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:95)
    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:78)
    at org.jboss.ejb.client.EJBClientContext.(EJBClientContext.java:77)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:13)

    Thanks,
    Sahitya

    • Sahitya

      Issue resolved.I had multiple jboss server runtimes and the runtime in this project was pointed to a older version and i was following steps for latest. I fixed that and ran the tutorial. It worked fine.

      Thanks for the tutorial.

  • Owais

    Dear praveen,

    now i am getting this error Could not find the main class:com.ibytecode.client.EJBApplicationClient. program will exit……..
    this error is generated by JVM.

    in eclipse i got the error

    java.lang.NoClassDefFoundError: com/ibytecode/client/EJBApplicationClient
    Caused by: java.lang.ClassNotFoundException: com.ibytecode.client.EJBApplicationClient
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)

    Plese help me to remove this error.

    Thanks
    Owais

  • Dana Peele

    I am using JBoss AS 7.1 and Eclipse Juno and am getting the following error when I try to access a simple session bean on the JBoss server from a standalone client in Eclipse. I added jboss-client.jar from C:\jboss-as-7.1.1.Final\bin\client to my build path and under the src directory I created jboss-ejb-client.properties as:
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=localhost
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

    My standalone is as follows:
    package test;

    import beans.*;
    import java.util.Properties;
    import javax.naming.InitialContext;
    import javax.naming.Context;

    public class BeanTest2 {
    public static void main (String[] args) throws Exception {
    Properties properties = new Properties();
    properties.put(Context.URL_PKG_PREFIXES, “org.jboss.ejb.client.naming”);
    InitialContext initialContext = new InitialContext(properties);
    RandomNumber2 randomNumber2 = (RandomNumber2)initialContext.lookup(“java:global/RandomNumberEJB/RandomNumber2Bean”);
    randomNumber2.setupNum(100000);
    System.out.printf(“Random with range: %5.2f.%n”, randomNumber2.currentValue());
    randomNumber2.doubleNum();
    System.out.printf(“Random with range: %5.2f.%n”, randomNumber2.currentValue());
    randomNumber2.done();
    }
    My stack trace is as follows:
    org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No
    at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
    at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
    at $Proxy24.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:257)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:270)
    at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:223)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:393)
    at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
    at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1241)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:411)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at test.BeanTest2.main(BeanTest2.java:15)
    Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:340)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:242)
    … 14 more
    Caused by: java.net.ConnectException: Connection refused: connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:364)
    at sun.nio.ch.Net.connect(Net.java:356)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
    at com.sun.corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java:110)
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:325)
    … 15 more
    Exception in thread “main” javax.naming.NamingException: Lookup failed for ‘java:global/RandomNumberEJB/RandomNumber2Bean’ in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at test.BeanTest2.main(BeanTest2.java:15)
    Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    … 3 more
    Caused by: org.omg.CORBA.COMM_FAILURE: FINE: IOP00410001: Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: localhost; port: 3700 vmcid: OMG minor code: 1 completed: No
    at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:248)
    at com.sun.corba.ee.spi.orbutil.logex.corba.CorbaExtension.makeException(CorbaExtension.java:95)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.handleFullLogging(WrapperGenerator.java:387)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator.access$400(WrapperGenerator.java:107)
    at com.sun.corba.ee.spi.orbutil.logex.WrapperGenerator$2.invoke(WrapperGenerator.java:511)
    at com.sun.corba.ee.spi.orbutil.proxy.CompositeInvocationHandlerImpl.invoke(CompositeInvocationHandlerImpl.java:99)
    at $Proxy24.connectFailure(Unknown Source)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:257)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:270)
    at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:129)
    at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:223)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:228)
    at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:393)
    at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:130)
    at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
    at com.sun.enterprise.naming.impl.SerialContext$ProviderCacheKey.getNameService(SerialContext.java:1241)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:411)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    … 4 more
    Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:340)
    at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.(SocketOrChannelConnectionImpl.java:242)
    … 14 more
    Caused by: java.net.ConnectException: Connection refused: connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:364)
    at sun.nio.ch.Net.connect(Net.java:356)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
    at com.sun.corba.ee.impl.orbutil.ORBUtility.openSocketChannel(ORBUtility.java:110)
    at org.glassfish.enterprise.iiop.impl.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:325)

  • leyson castaño

    hola me gustaría que me ayudaras es que estoy haciendo esta guía y me funciono pero al agregar los jars a maven no funciona lo mismo me sale un error Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial y gracias por la ayuda

    • http://theopentutorials.com Praveen Macherla

      May be some problem in dependencies. Also check whether the ejb project is deployed in the server.

  • Avase

    Hi,

    Great tutorial for begineers. Keep it up.

  • Swaroop

    Hi,

    Can we invoke a EJB service from Android directly.
    Do we need to expose EJB client as a webservice and call from android to EJBService?
    Am not pretty sure how we can achieve this.Let me know on the same

    • http://theopentutorials.com Praveen Macherla

      Expose it as a web service or provide a front end (servlet/jsp) which accesses ejb.

      • Swaroop

        Hi,

        Thanks for the reply.
        I tried the first option and its working fine.
        Very good tutorials.

      • Uttam

        Hi Praveen
        I have followed the steps mentioned in this tutorial. I am getting the below error. Please help me.
        Authentication failed: all available authentication mechanisms failed

        Thanks,
        Uttam Das

        • http://theopentutorials.com Praveen Macherla

          Check 6.4 in this link

  • rkmvjti

    I have added jboss-ejb-client.properties in ejbmodule and set all requiredjar in classpath .I am using jboss 7.1.I am still getting same error
    avax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initialHellowolrdClient.lookupContext()imputcontextnull
    HellowolrdClient.getlookupName()

    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getNameInNamespace(InitialContext.java:538)

  • Raul

    Thanks a lot. Worked with jboss 7.1.0.

  • Seetesh

    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:sb01,modulename:sb01,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@1a0c10f
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.add(Unknown Source)
    at EJBApplicationClient.main(EJBApplicationClient.java:18)

    • Dibyendu

      Have you found the solution, I am also facing the same issue.

  • Nick

    Great tutorial! Thank you very much.
    I used JBoss Version 7.1.1 Final and struggled a little bit as the client told the error:
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available

    Then I found out, that the application was not deployed correctly. To have it deployed I had to create a file HelloWorldSessionBean.jar.dodeploy in the deployment directory of the jboss server.

  • Sujith

    I am using jboss-6.1.0.Final, and am also facing this issue, I don’t see few of the jars mentioned in this example, any help would be appreciated

    • http://theopentutorials.com Nithya Vasudevan

      Go through this link for EJB3 in JBoss 6.1

  • Pingback: How To Develop Android Apps In Eclipse | X Power Ionizer Post

  • John

    I am trying to follow your example but I am getting the following errors:

    It looks like it cant find the imports for the ejb stuff

    Description Resource Path Location Type
    Remote cannot be resolved to a type HelloWorldBean.java /HelloWorldSessionBean/ejbModule/com/ibytecode/businesslogic line 5 Java Problem.

    Description Resource Path Location Type
    The import javax.ejb cannot be resolved HelloWorldBean.java /HelloWorldSessionBean/ejbModule/com/ibytecode/businesslogic line 3 Java Problem

  • raterosh

    I am using jBoss 5.0 , where could i find the jar files that are added in the last step.
    I have tried searching these files but i could not. Help me out. Thanks

    • http://theopentutorials.com Praveen Macherla

      See this link for the steps to create an ejb3 project for JBoss 5.1

  • Abhishek D

    Hi. Great Tutorial. But Ctrl + F11 produces “Usage: javaw [-options] class [args...] (to execute a class)”

    I also have JDK 1.6 configured and JRE 7 from Window -> preferences. I shut down eclipse, re-started the JBoss server and repeated, but still I get the same message.

  • naresh

    Hi!

    This is Naresh, i am tried above application using Eclipse Indigo, JBoss7.1, it showing Exception… can you plz tell me wt hpn…

    like:

    INFO: JBoss Remoting version 3.2.0.CR6
    javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Operation failed with status WAITING]
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.init(InitialContext.java:223)
    at javax.naming.InitialContext.(InitialContext.java:197)
    at com.ariveguru.ejb.ClientUtility.getInitialContext(ClientUtility.java:25)
    at com.ariveguru.ejb.EjbApplicationClient.doLookup(EjbApplicationClient.java:20)
    at com.ariveguru.ejb.EjbApplicationClient.main(EjbApplicationClient.java:11)
    Caused by: java.lang.RuntimeException: Operation failed with status WAITING
    at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
    at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
    … 7 more
    Exception in thread “main” java.lang.NullPointerException
    at com.ariveguru.ejb.EjbApplicationClient.main(EjbApplicationClient.java:12)

  • Aditya Amgaonkar

    Hey Nithya thanks for such a wonderful & perfect guide for creating EJB 3.0 project.
    Great Efforts!!!!
    Could you please help me further!
    I wanted to add an JPA project to this EJB project how shall I do it?
    Database used by me is Oracle 11g.
    I have tried many ways but I am unable to get over several problems.
    Also like to inform that i am an beginner to JavaEE.

    • http://theopentutorials.com Nithya Vasudevan

      You can refer this link for EJB3 JPA Project. But it uses MySQL. If you want to know the connection string for Oracle, refer this link.

  • Kumaresh

    Thanks for this informative tutorial. This example is working for me with properties file.

  • Nilanka

    Mar 7, 2013 12:28:53 PM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.5.Final
    Mar 7, 2013 12:28:53 PM org.xnio.Xnio
    INFO: XNIO Version 3.0.3.GA
    Mar 7, 2013 12:28:53 PM org.xnio.nio.NioXnio
    INFO: XNIO NIO Implementation Version 3.0.3.GA
    Mar 7, 2013 12:28:53 PM org.jboss.remoting3.EndpointImpl
    INFO: JBoss Remoting version 3.2.3.GA
    Mar 7, 2013 12:28:54 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
    INFO: Received server version 1 and marshalling strategies [river]
    Mar 7, 2013 12:28:54 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
    INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@9446e4, receiver=Remoting connection EJB receiver [connection=Remoting connection ,channel=jboss.ejb,nodename=laptop]} on channel Channel ID dc2db15c (outbound) of Remoting connection 00b60b93 to localhost/127.0.0.1:4447
    Mar 7, 2013 12:28:54 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage
    WARN: Unsupported message received with header 0xffffffff

    what can i do?

    • http://theopentutorials.com Nithya Vasudevan

      Read the previous comments. Check your JBoss version and try to add the correct client JAR file to the classpath.

      • shanmukha

        Hi nithya ,

        i add the proper jar file still i am getting the same exception

        please find the error trace and help me out with proper solution
        what to do now

        Oct 27, 2013 4:01:06 PM org.jboss.ejb.client.EJBClient

        INFO: JBoss EJB Client version 1.0.2.Final

        lookup success

        Oct 27, 2013 4:01:06 PM org.xnio.Xnio

        INFO: XNIO Version 3.0.3.GA

        Oct 27, 2013 4:01:06 PM org.xnio.nio.NioXnio

        INFO: XNIO NIO Implementation Version 3.0.3.GA

        Oct 27, 2013 4:01:06 PM org.jboss.remoting3.EndpointImpl

        INFO: JBoss Remoting version 3.2.2.GA

        Oct 27, 2013 4:01:06 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

        INFO: Received server version 1 and marshalling strategies [river]

        Oct 27, 2013 4:01:06 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

        INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@4580d050, receiver=Remoting connection EJB receiver [connection=Remoting connection ,channel=jboss.ejb,nodename=us-pc]} on channel Channel ID 8cce2a01 (outbound) of Remoting connection 1e71b324 to localhost/127.0.0.1:4447

        Oct 27, 2013 4:01:06 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

        WARN: Unsupported message received with header 0xffffffff

        Exception in thread “main” javax.ejb.NoSuchEJBException: No such EJB[appname=,modulename=HelloWorldSessionBean,distinctname=,beanname=HelloWorldBean]

        at org.jboss.ejb.client.remoting.GeneralInvocationFailureResponseHandler.processMessage(GeneralInvocationFailureResponseHandler.java:75)

        at org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver.handleMessage(ChannelAssociation.java:385)

        at org.jboss.remoting3.remote.RemoteConnectionChannel$5.run(RemoteConnectionChannel.java:435)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

    • shanmukha

      i am facing the same problem ,did you get the solution for the same ,if you got the solution
      please help to resolve this my email id :[email protected];[email protected]

  • Nilanka

    i still get the warnings, but i could run the client, thank you very much for the support.

    The EJB series is the best complete series of EJB tutorials i have ever seen.

    Great job.

  • heta

    Hi Nithya and ALL,

    I have been following your tutorial from 2 days, i want to work with JPA so i started with basic step by creating simple “Hello worldBean” by following your tutorial, i setted – up environment as you said, my server starts fine, http://localhost … shows my jboss page, but when i try to deploy ejbbean on server, it is not being deployed, i mean i dont get any message on console (which you specified in your tutorial), nor any errors, i checked both jboss/server/default/ and http://localhost:8080/jms- console/jndiview but couldnt see any entries of my jar file. I tried using jboss 4.22,5.1.0 and 6.x but same thing happens, Please help.

    Thanks
    Heta

  • vikram d

    I am new for EJB n also go through above steps but I got same error, so please let me know in case of any solution.

  • vikram d

    I am new for EJB n also go through above steps but I got error
    Error: Could not find or load main class com.ibytecode.client.EJBApplicationClient

    , so please let me know in case of any solution.

  • amar nath

    I am facing this problem while writing the above code and run in jboss 7.1

    Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;

  • http://www.facebook.com/altanai altanai

    when runing server i get the traces as folows –
    12:13:16,933 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment testejb.jar in 40ms
    12:13:16,934 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015876: Starting deployment of “testejb.jar”
    12:13:16,951 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named HelloWorldBean in deployment unit deployment “testejb.jar” are as follows:

    java:global/testejb/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:app/testejb/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:jboss/exported/testejb/HelloWorldBean!com.ibytecode.business.HelloWorld
    java:global/testejb/HelloWorldBean
    java:app/testejb/HelloWorldBean
    java:module/HelloWorldBean

    12:13:17,093 INFO [org.jboss.as.server] (DeploymentScanner-threads – 2) JBAS018565: Replaced deployment “testejb.jar” with deployment “testejb.jar”

    which is right but on runing the EJB applicationClient.java as java program i get the errors as

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.ibytecode.client.EJBApplicationClient.doLookup(EJBApplicationClient.java:26)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:13)
    Exception in thread “main” java.lang.NullPointerException
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:14)

    please show me a way to run the program correctly

  • ta_shuo

    Very Good~mark

  • Dr Schuh

    I put my properties file in the root project folder.
    It will return a “No EJB Receiver available” exception.

    I can’t place the “jboss-ejb-client.properties” File in the ejbModule folder of the application. I tried to put more properties to the initialContext properties, so I wouldn’t need the file, but it didn’t work out either.

    Where do I have to place the jboss-ejb-client.properties file? I think it’s causing the exception

  • Kumar Roushan

    Hi Nithya,
    Thanks for your EJB 3.0 tutorial ,it is helping me alot.
    Please provide some Working sample to show the difference between stateless and stateful session bean and converting a session bean to webservice.

    Regards,
    Kumar Roushan

  • firene98

    Great tutorial – Many thanks!!

  • prashant gandhi

    Hi Nithya, Thanks for sharing this. I am very new to Java/EJB world. I have followed all the steps mentioned. I am trying to use JBOSS AS 7.1.1 Final. The server is up and running. My jboss-ejb-client.properties file is directly under the ejbModule folder. I have included only 1 .jar file in classpath as mentioned (jboss-client.jar from AS_HOME/bin/client) But, I am getting below error.

    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@166aa18
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at $Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:18)

    Can you please tell me what am i doing wrong? I get above error message when I do control + F11 on the main project after following all your steps.

    How do i ensure that jboss-ejb-client.properties is in classpath?

    Thanks for all your help.

  • prashant gandhi

    also, how do i ensure that the ejb is deployed properly? do i have to pick any file from ejb world and place it in jboss as 7.1.1 final server somewhere? i just followed all the steps mentioned above and ctrl + F11 would throw the errors that i mentioned above.

    in existing application (jboss 4.0.1 sp1 and ejb2), when we compile the code, it creates the .ear file that we put on jboss 4.0.1 sp1 server/default/deploy directory and then start the jboss server to see the output webpage..

    isn’t that something similar here? if so, what .ear or .jar file are we supposed to put and what is the source/destination for it?

  • prashant gandhi

    so i figured it out. i did not make any change, just closed the eclipse and re-opened it, restarted the jboss server and all worked fine.

    I am trying to learn ejb these days, and am trying to create a new bean inside this application but this time @local. this bean is a copy of the existing HelloWorld bean and supposed to print “hello world from local bean”. however the application fails for this bean saying proxy0 error. I believe it is failing because jboss-ejb-client.property has port listed as 4447 which is strictly remote as i understand from the above discussion. if that is the case, then some further change will be required for making it work for local bean as well in the same application.

    Can someone tell me how to go about it? any pointers will be appreciated. Thanks.

    • Sandeep

      After creating the properties file externally, the project has to be refreshed for the properties file to load into project.

  • Mahesh Kumar

    Hi Nithya,

    I followed your JPA tutorial and implemented the steps. But I am getting error as “No EJB receiver available”. I used jboss7.1.1-Final, Eclipse JEE Juno IDE and MySQL database. Please help me out on this.

    Thanks,
    Mahesh

  • Kaveh

    Hi,
    thank you for the tutouial.
    I get the following error, whenn I run my ejb remote client:

    Jun 21, 2013 2:23:14 PM org.xnio.Xnio
    INFO: XNIO Version 3.0.0.CR5
    Jun 21, 2013 2:23:14 PM org.xnio.nio.NioXnio
    INFO: XNIO NIO Implementation Version 3.0.0.CR5
    Jun 21, 2013 2:23:14 PM org.jboss.remoting3.EndpointImpl
    INFO: JBoss Remoting version 3.2.0.CR6
    Jun 21, 2013 2:23:14 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
    INFO: Received server version 1 and marshalling strategies [river]
    Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.remoting3.Channel.getOption(Lorg/xnio/Option;)Ljava/lang/Object; at org.jboss.ejb.client.remoting.ChannelAssociation.(ChannelAssociation.java:118) at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.associate(RemotingConnectionEJBReceiver.java:158) at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:297) at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:252) at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:128) at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:78) at org.jboss.ejb.client.EJBClientContext.(EJBClientContext.java:77) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) at $Proxy0.isValidSerialNumberRemoteMethod(Unknown Source) at ejb.kap01.remote.client.RemoteClient.main(RemoteClient.java:40)
    Jun 21, 2013 2:23:14 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage
    WARN: Unsupported message received with header 0xffffffff
    Jun 21, 2013 2:23:14 PM org.xnio.Xnio

    INFO: XNIO Version 3.0.0.CR5

    Jun 21, 2013 2:23:14 PM org.xnio.nio.NioXnio

    INFO: XNIO NIO Implementation Version 3.0.0.CR5

    Jun 21, 2013 2:23:14 PM org.jboss.remoting3.EndpointImpl

    INFO: JBoss Remoting version 3.2.0.CR6

    Jun 21, 2013 2:23:14 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

    INFO: Received server version 1 and marshalling strategies [river]

    Exception in thread “main” java.lang.NoSuchMethodError: org.jboss.remoting3.Channel.getOption(Lorg/xnio/Option;)Ljava/lang/Object;

    at org.jboss.ejb.client.remoting.ChannelAssociation.(ChannelAssociation.java:118)

    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.associate(RemotingConnectionEJBReceiver.java:158)

    at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:297)

    at org.jboss.ejb.client.EJBClientContext.registerEJBReceiver(EJBClientContext.java:252)

    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:128)

    at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.(ConfigBasedEJBClientContextSelector.java:78)

    at org.jboss.ejb.client.EJBClientContext.(EJBClientContext.java:77)

    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)

    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

    at $Proxy0.isValidSerialNumberRemoteMethod(Unknown Source)

    at ejb.kap01.remote.client.RemoteClient.main(RemoteClient.java:40)

    Jun 21, 2013 2:23:14 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage

    WARN: Unsupported message received with header 0xffffffff

    My jboss-ejb-client.properties file looks like this:

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=127.0.0.1
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

    can you help me to fix the problem?

  • Ashwin Raghavan

    Nice Article

    I have two questions.
    1) how does the JNDI names get added automatically. Where can I see those entries.
    2) Where is ejb-jar.xml in my eclipse project.

  • daniele

    This saved my day. Thanks.

  • Malik Shah Jahan

    Hi
    I had been searching the web for last 1 week in order to find a nice EJB/ Eclipse tutorial that actually works, easy to understand and comprehensively explaining each and every term as well as technology. This 1 page tutorial is a complete book on EJBs in itself.

    Hats off to Nithya.

  • mahmoud

    Hi,
    thank you for the tutouial.
    I get the following error, whenn I run my ejb remote client:
    **********************************************************

    12 août 2013 14:44:12 org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.2.Final
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:530)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:84)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy0.sayHello(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:14)

  • Learner

    Hello Nithya,
    I prepared sample application based on your tutorial. But I get error that no EJB receiver handler. Following is my code:

    package com.cts;

    import java.util.List;

    import javax.ejb.Remote;

    @Remote
    public interface LibrarySessionBeanRemote {

    void addBook(String name);

    List getBooks();

    }

    ——————————————————————–

    package com.cts;

    import java.util.ArrayList;
    import java.util.List;

    import javax.ejb.Stateless;

    /**
    * Session Bean implementation class LibrarySessionBean
    */
    @Stateless
    public class LibrarySessionBean implements LibrarySessionBeanRemote {

    List bookShelf;

    /**
    * Default constructor.
    */
    public LibrarySessionBean() {
    bookShelf = new ArrayList();
    }

    @Override
    public void addBook(String name) {
    bookShelf.add(name);
    }

    @Override
    public List getBooks() {
    return bookShelf;
    }

    }

    ————————————————————————-

    package com.cts;

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.Properties;

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

    public class EJBTester {

    Properties props;

    public EJBTester() {
    props = new Properties();
    try {
    props.load(new FileInputStream(“jndi.properties”));
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    EJBTester test = new EJBTester();
    test.callEjb();
    }

    public void callEjb() {
    try {
    Properties props = new Properties();
    props.put(Context.URL_PKG_PREFIXES, “org.jboss.ejb.client.naming”);
    props.put(“jboss.naming.client.ejb.context”, true);
    final Context context = new InitialContext(props);
    final String appName = “”;
    final String moduleName = “EjbComponent”;
    final String distinctName = “”;
    final String beanName = LibrarySessionBean.class.getSimpleName();
    final String viewClassName = LibrarySessionBeanRemote.class.getName();
    System.out.println(“ejb:” + appName + “/” + moduleName + “/” + distinctName + “/” + beanName + “!” + viewClassName);
    LibrarySessionBeanRemote lsbr = (LibrarySessionBeanRemote) context.lookup(“ejb:” + appName + “/” + moduleName + “/”
    + distinctName + “/” + beanName + “!”
    + viewClassName);
    lsbr.addBook(“The Wedding”);
    System.out.println(lsbr.getBooks());
    } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }

    ————————————————————————

    Point to note is that, my client is in separate project. Client has jboss-ejb-client.properties file in classpath. My session bean is deplozed successfully. Below are the server logs:

    11:32:59,892 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.0.Final “Thunder” started in 3966ms – Started 134 of 205 services (70 services are passive or on-demand)
    11:33:02,005 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) JBAS015012: Started FileSystemDeploymentService for directory D:eclipseworkspace.metadata.pluginsorg.jboss.ide.eclipse.as.corejboss-as-7.1.0.Finaldeploy
    11:33:37,043 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads – 1) JBAS015003: Found EjbComponent.jar in deployment directory. To trigger deployment create a file called EjbComponent.jar.dodeploy
    11:33:37,072 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of “EjbComponent.jar”
    11:33:37,213 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named LibrarySessionBean in deployment unit deployment “EjbComponent.jar” are as follows:

    java:global/EjbComponent/LibrarySessionBean!com.cts.LibrarySessionBeanRemote
    java:app/EjbComponent/LibrarySessionBean!com.cts.LibrarySessionBeanRemote
    java:module/LibrarySessionBean!com.cts.LibrarySessionBeanRemote
    java:jboss/exported/EjbComponent/LibrarySessionBean!com.cts.LibrarySessionBeanRemote
    java:global/EjbComponent/LibrarySessionBean
    java:app/EjbComponent/LibrarySessionBean
    java:module/LibrarySessionBean

    11:33:37,381 INFO [org.jboss.as.server] (DeploymentScanner-threads – 2) JBAS018559: Deployed “EjbComponent.jar”

    ——————————————————————————-

    In client console I see:

    ejb:/EjbComponent//LibrarySessionBean!com.cts.LibrarySessionBeanRemote
    Sep 8, 2013 11:34:49 AM org.jboss.ejb.client.EJBClient
    INFO: JBoss EJB Client version 1.0.0.Beta11
    Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:EjbComponent,distinctname:] combination
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:344)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:92)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:83)
    at $Proxy0.addBook(Unknown Source)
    at com.cts.EJBTester.callEjb(EJBTester.java:49)
    at com.cts.EJBTester.main(EJBTester.java:31)

    ———————————————————————

    I am struggling with this issue for past two days. Please help me to resolve it.

  • Learner

    I forgot to mention jboss-ejb-client.properties file contents. Here they are:

    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=localhost
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
    remote.connection.default.username=admin
    remote.connection.default.password=jboss

    I have user created on my jboss with these credentials.

  • guest

    no one could present it better than this.u should be a nice person.

  • Federico

    That’s an Excellent tutorial.
    It works, it is well explained, you can copy and paste the code easily. Besides, all imports are detailed on each class.
    It’s simple, but very good quality.
    Thank you.

  • shanmukha

    hi nithya
    i am facing issues when i am connecting ejb application from client and that are classcast exception
    and illegal state exception and please find the client classes and could you able to notice what
    really went wrong in client class
    java:global/EjbProject3/MySessionBean!mypack.MySessionBeanRemote
    java:app/EjbProject3/MySessionBean!mypack.MySessionBeanRemote
    java:module/MySessionBean!mypack.MySessionBeanRemote
    java:jboss/exported/EjbProject3/MySessionBean!mypack.MySessionBeanRemote
    java:global/EjbProject3/MySessionBean
    java:app/EjbProject3/MySessionBean
    java:module/MySessionBean

  • Dibyendu

    Hi All,

    I am getting the same errors that many have got “No EJB receiver available for handling”

    I have tried to find the solution and found that

    properties.put(“jboss.naming.client.ejb.context”, true); is to be added. This solution have worked for almost all but not working for me please tell me what might be the reason and some one can please tell me what is the purpose of standalone.xml

  • gokul86

    holy mother of sweet jesus
    it worked
    thanks
    i am running kepler + jboss 7.1

  • Victor Elliott

    Thanks very much, it help me a lot in my house project …

  • Clay Ferguson

    Thank you for posting this tutorial! It worked perfectly!

  • dung.phan

    Hi Prashant gandhi
    You have got the error “Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling”

    because you using the code
    // 2. Generate JNDI Lookup name
    String lookupName = getLookupName();
    I think you provided the name JNDI wrong,
    if the name for JNDI is wrong , it will can not get EJB for you . —> this error

  • dung.phan

    Hi Prashant gandhi
    You have got the error “Exception in thread “main” java.lang.IllegalStateException: No EJB receiver available for handling”

    because you using the code
    // 2. Generate JNDI Lookup name
    String lookupName = getLookupName();
    I think you provided the name JNDI wrong,
    if the name for JNDI is wrong , it will can not get EJB for you . —> this error

    • Guest

      I didn’t know much about ejb and jndi .Can you please tell me correct lookupname for this example

      Thanks

  • Andy Soloman

    Thanks. It is working!

  • Lai Kuan Wong

    Hi Nithya, Thanks a lot for sharing this … such a great tutorial! You saved my day :)

  • Trancendental

    I found a fix for my “No EJB receiver available for handling” error.
    I was missing the @Remote line in HelloWorld.java (this should be right above the interface)

    Anyone getting this error, try looking for any warnings in your code. The complete project should not have any warnings.

    I believe that to ensure the properties file is in the classpath you can right-click on the HelloWorldSessionBean Project, select Properties, select Java Build Path, and then select source. Here you should see HelloWorldSessionBean/ejbModule (if it’s not there choose Add Folder to add it). If your properties file is located at this level it is in the classpath and therefore should be picked up.

    Hopefully this helps, I was stuck for several hours on this.

    The tutorial works, you just have to follow it exactly.