Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
    Bookmark Topic Watch Topic
  • New Topic

Elementary Query around EJB3 and JBoss

Anoop Jain
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi All,

Am trrying to deploy an EJB-3 stateless bean on JBoss but am unable to do that. Will appreciate if anyone can let me know what's wrong. In did the following:

[1] Created Bean and Local/Remote Interfaces:-
public interface CalcRemote {

public double add(double a, double b);

public double substract(double a, double b);

public double multiply(double a, double b);

public double divide(double a, double b);

public class Calc implements CalcLocal, CalcRemote {

public double add(double a, double b) {
return a+b;

public double divide(double a, double b) {
return a-b;

public double multiply(double a, double b) {
return a*b;

public double substract(double a, double b) {
return a/b;

[2] Created a client to test the above:
public class Client
public static void main(String [] args) throws Exception
CalcRemote cal = (CalcRemote) getInitialContext().lookup("Calc/remote");

System.out.println(cal.add(1.2, 3.4));

public static Context getInitialContext()
throws javax.naming.NamingException
return new javax.naming.InitialContext();

[3] The client will have the following in its classpath


[4] Created an application.xml file to be used for EAR

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns=""

[5] Created a build.xml that will package an EAR file and will place the EAR in the JBoss-default folder:
<project name="JBoss" default="ejbjar" basedir=".">

<property environment="env"/>
<property name="src.dir" value="${basedir}"/>
<property name="src.resources" value="${basedir}/resources"/>
<property name="jboss.home" value="${env.JBOSS_HOME}"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="build.classes.dir" value="${build.dir}/classes"/>

<!-- Build classpath -->
<path id="classpath">
<fileset dir="${jboss.home}/server/default/lib">
<include name="*.jar"/>
<fileset dir="${jboss.home}/server/default/deploy/jboss-bean.deployer">
<include name="*.jar"/>
<fileset dir="${jboss.home}/server/default/deploy/jboss-aop.deployer">
<include name="*.jar"/>
<fileset dir="${jboss.home}/lib">
<include name="*.jar"/>
<fileset dir="${basedir}/lib">
<include name="*.jar"/>
<pathelement location="${build.classes.dir}"/>
<!-- So that we can get for InitialContext and log4j.xml file -->
<pathelement location="${basedir}/client-config"/>

<property name="build.classpath" refid="classpath"/>

<target name="prepare" >
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes.dir}"/>

<target name="compile" depends="prepare">
<javac srcdir="${src.dir}"
<classpath refid="classpath"/>

<target name="ejbjar" depends="compile">
<jar jarfile="build/calc.jar">
<fileset dir="${build.classes.dir}">
<include name="com/anoop/ejb3/beans/*.class"/>
<ear zipfile="build/calc.ear" appxml="${src.resources}/application.xml">
<fileset dir="build">
<include name="calc.jar"/>
<copy file="build/calc.ear" todir="${jboss.home}/server/default/deploy"/>


[6] AFter running the build file, I can see the following JBoss server console:

17:56:27,658 INFO [EARDeployer] Init J2EE application: file:/H:/jboss-4.0.4/server/default/deploy/calc.ear
17:56:28,017 INFO [EARDeployer] Started J2EE application: file:/H:/jboss-4.0.4/server/default/deploy/calc.ear

[7] However there is no entry corresponding to the Calc bean/interfaces in the JNDIView MBean on the JMX Console.

[8] And consequently when I run the client it fails:-

Exception in thread "main" javax.naming.NameNotFoundException: Calc not bound
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getBinding(
at org.jnp.server.NamingServer.getObject(

Any help will be hugely appreciated.
Jaikiran Pai
Posts: 10447
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Let's continue this discussion in your other thread
    Bookmark Topic Watch Topic
  • New Topic