Bookmark Topic Watch Topic
  • New Topic

Elementary Query around EJB3 and JBoss  RSS feed

 
Anoop Jain
Greenhorn
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:-
@Remote
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);
}

@Stateless
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 jndi.properties in its classpath

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.namingrg.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099

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

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<display-name>calc</display-name>
<module>
<ejb>calc.jar</ejb>
</module>
</application>

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

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

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

<target name="compile" depends="prepare">
<javac srcdir="${src.dir}"
destdir="${build.classes.dir}"
debug="on"
deprecation="on"
optimize="off"
includes="**">
<classpath refid="classpath"/>
</javac>
</target>

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

</project>

[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(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)


Any help will be hugely appreciated.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Let's continue this discussion in your other thread http://www.coderanch.com/t/450097/JBoss/Elementary-Query-around-JBoss-EJB
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!