Advertisement

10.02.2005 at 10:33PM PDT, ID: 21581508
[x]
Attachment Details

Problem while Calling EJB in JBoss4.0 using Eclipse3.1

Asked by dinesh_bali in Application Servers

Tags:

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.java
/src/examples/HelloBean.java
/src/examples/HelloLocal.java
/src/examples/HelloLocalHome.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,RemoteException;
}


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("ejbCreate");
    }
    public void ejbActivate() throws EJBException, RemoteException
    {
        System.out.println("ejbActivate");  
    }

    public void ejbPassivate() throws EJBException, RemoteException
    {
        System.out.println("ejbPassivate");
    }

    public void ejbRemove() throws EJBException, RemoteException
    {
        System.out.println("ejbRemove");        
    }

    public void setSessionContext(SessionContext 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.PortableRemoteObject;
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.factory.initial",
            "org.jnp.interfaces.NamingContextFactory");
         env.put("java.naming.factory.url.pkgs",
            "org.jboss.naming:org.jnp.interfaces");
         env.put("java.naming.provider.url",
            "localhost");       
         InitialContext context = new InitialContext(env);
      //  Context ctx = new InitialContext(env);
       // Object obj=ctx.lookup("java:comp/env/Hello");
        //HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
       HelloHome home = (HelloHome) context.lookup("Hello");
        Hello hello=home.create();
        System.out.println(hello.hello());      
        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</remote>
         <local-home>examples.HelloLocalHome</local-home>
         <local>examples.HelloLocal</local>
         <ejb-class>examples.HelloBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-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-name>
         <local-jndi-name>HelloLocal</local-jndi-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\default\deploy>java examples.HelloClient
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Log
ger
        at org.jnp.interfaces.NamingContext.<clinit>(NamingContext.java:101)
        at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingConte
xtFactory.java:41)
        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
        at javax.naming.InitialContext.init(Unknown Source)
        at javax.naming.InitialContext.<init>(Unknown Source)
        at examples.HelloClient.main(HelloClient.java:25)
can some body help me
Start Free Trial
 
Loading Advertisement...
 
[+][-]10.04.2005 at 12:55PM PDT, ID: 15017168

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Application Servers
Tags: ejb
Sign Up Now!
Solution Provided By: ramazanyich
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.12.2005 at 04:21AM PDT, ID: 15067701

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.12.2005 at 04:25AM PDT, ID: 15067715

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.21.2005 at 03:12AM PDT, ID: 15131077

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.26.2005 at 11:36AM PST, ID: 15551797

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12.30.2005 at 05:12AM PST, ID: 15577380

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32