开发者

How to access an EJB?

I am trying to develop a Basic EJB3 application on JBOSS 4.2 in Eclipse

I have created an EJB project in eclipse.

The following are my remote and local interfaces.

package com.test;
import javax.ejb.Local;

@Local
public interface HelloWorldLocal 
{
  public String getGreeting();
}

package com.test;
import javax.ejb.Remote;

@Remote
public interface HelloWorldRemote 
{
   public String getGreeting();
}

and my ejb implementation is

package com.test;
import javax.ejb.Stateless;

@Stateless
 public class HelloWorld implements HelloWorldRemote, HelloWorldLocal {


public HelloWorld() {
    // TODO Auto-generated constructor stub
}

public String getGreeting() {
    // TODO Auto-generated method stub
    return "First EJB People";
}

}

I have deployed this as an exploded JAR in JBoss and it runs fine.

My first question is:

What else do I have to add to this exploded jar ?

Secondly I created a stand alone client and added the above jar to its classpath

The client code is as follows

package com.testejb;

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

import javax.naming.InitialContext;

public class TestBean {

/**
 * @param args
 */
public static void main(String[] args) 
{
    // TODO Auto-generated method stub
      HelloWorldRemote getMess = null;
      try {
          Properties props = new Properties();
            Properties props = new Properties();
             props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
            props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
            props.setProperty("java.naming.provider.url", "localhost:1099"); 

          InitialContext ic = new InitialContext(props);

          //


          getMess = (HelloWorldRemote) ic.lookup("HelloWorldRemote/remote");
          System.out.println(getMess.getGreeting());
    } catch (Exception e) 
    {
        // TODO: handle exception
        e.printStackTrace();
    }

}

}

The name of the jar is FirstEJB. I have tried the look up as FirstEJB/HelloWorldRemote/remote.

But when I run the program I get the error

javax.naming.NameNotFoundException: HelloWorldRemote not bound

If I type the lookup as HelloWorld/remote i get the error

Caused by: java.io.InvalidClassException: org.jboss.ejb3.remoting.BaseRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 1126421850898582900, loca开发者_运维技巧l class serialVersionUID = -2711693270411201590


What else do I have to add to this exploded jar ?

Nothing, it's usable.

I have tried the look up as FirstEJB/HelloWorldRemote/remote

With JBoss, the JNDI name will be:

<myEarName>/<EJB-Name>/remote

Where the EJB-Name defaults to the Bean name if not specified. So in your case, without using an EAR packaging, the JNDI name should be:

HelloWorld/remote

This should be logged in the server logs at deployment time by the way.

If I type the lookup as HelloWorld/remote I get the error (...)

The JNDI name used for the lookup is correct, this error is another problem that looks very similar to EJBTHREE-1118. Could you try with JBoss 4.2.3.GA?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜