Dear Friends,
I am making simple stateless bean. Which prints only Hello World. Code given in Willey's Mastering Enterprise JavaBeans
What I am doing is given below:
My Files is stored in location:
/src/examples/Hello.java
/src/examples/HelloHome.ja
va
/src/examples/HelloBean.ja
va
/src/examples/HelloLocal.j
ava
/src/examples/HelloLocalHo
me.java
My Client file through which I am calling the Bean is stored in:
/src/examples/HelloClient.
java
My JBoss and Ejb-Jar.xml files are stored in Location:
/src/META-INF/ejb-jar.xml
/src/META-INF/jboss.xml
I am using Eclipse3.1 and Jboss4.0
Codes are given below:
Hello.java
package examples;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Hello extends EJBObject
{
public String hello() throws RemoteException;
}
HelloHome.java
package examples;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
public interface HelloHome extends EJBHome
{
public Hello create() throws CreateException,RemoteExce
ption;
}
HelloBean.java
package examples;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionContext;
public class HelloBean implements javax.ejb.SessionBean
{
private SessionContext ctx;
public void ejbCreate()
{
System.out.println("ejbCre
ate");
}
public void ejbActivate() throws EJBException, RemoteException
{
System.out.println("ejbAct
ivate");
}
public void ejbPassivate() throws EJBException, RemoteException
{
System.out.println("ejbPas
sivate");
}
public void ejbRemove() throws EJBException, RemoteException
{
System.out.println("ejbRem
ove");
}
public void setSessionContext(SessionC
ontext ctx) throws EJBException, RemoteException
{
this.ctx=ctx;
}
public String hello()
{
System.out.println("hello(
)");
return "Hello, World!";
}
}
HelloLocal.java
package examples;
public interface HelloLocal extends javax.ejb.EJBLocalObject
{
public String hello();
}
HelloLocalHome.java
package examples;
public interface HelloLocalHome extends javax.ejb.EJBLocalHome
{
HelloLocal create() throws javax.ejb.CreateException;
}
HelloClient.java
package examples;
import javax.naming.*;
import javax.rmi.PortableRemoteOb
ject;
import java.util.Properties;
import java.util.*;
public class HelloClient
{
public static void main (String[] args) throws Exception
{
//Properties props= new Properties();
//Properties props = System.getProperties();
Hashtable env = new Hashtable();
env.put("java.naming.facto
ry.initial
",
"org.jnp.interfaces.Naming
ContextFac
tory");
env.put("java.naming.facto
ry.url.pkg
s",
"org.jboss.naming:org.jnp.
interfaces
");
env.put("java.naming.provi
der.url",
"localhost");
InitialContext context = new InitialContext(env);
// Context ctx = new InitialContext(env);
// Object obj=ctx.lookup("java:comp/
env/Hello"
);
//HelloHome home=(HelloHome)PortableRe
moteObject
.narrow(ob
j,HelloHom
e.class);
HelloHome home = (HelloHome) context.lookup("Hello");
Hello hello=home.create();
System.out.println(hello.h
ello());
hello.remove();
}
}
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "
http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<enterprise-beans>
<session >
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</
home>
<remote>examples.Hello</re
mote>
<local-home>examples.Hello
LocalHome<
/local-hom
e>
<local>examples.HelloLocal
</local>
<ejb-class>examples.HelloB
ean</ejb-c
lass>
<session-type>Stateless</s
ession-typ
e>
<transaction-type>Containe
r</transac
tion-type>
</session>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "C:/jboss_4_0.dtd">
<jboss>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<jndi-name>Hello</jndi-nam
e>
<local-jndi-name>HelloLoca
l</local-j
ndi-name>
<method-attributes>
</method-attributes>
</session>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
After all this I am simply deploying my bean which gets deployed in Jboss.
But When I am running my client file HelloClient.java from Command Prompt or from Eclipse I am getting the error given below
C:\jboss-4.0.0\server\defa
ult\deploy
>java examples.HelloClient
Exception in thread "main" java.lang.NoClassDefFoundE
rror: org/jboss/logging/Log
ger
at org.jnp.interfaces.NamingC
ontext.<cl
init>(Nami
ngContext.
java:101)
at org.jnp.interfaces.NamingC
ontextFact
ory.getIni
tialContex
t(NamingCo
nte
xtFactory.java:41)
at javax.naming.spi.NamingMan
ager.getIn
itialConte
xt(Unknown
Source)
at javax.naming.InitialContex
t.getDefau
ltInitCtx(
Unknown Source)
at javax.naming.InitialContex
t.init(Unk
nown Source)
at javax.naming.InitialContex
t.<init>(U
nknown Source)
at examples.HelloClient.main(
HelloClien
t.java:25)
can some body help me
Start Free Trial