views:

24

answers:

2

Hi,

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, local class serialVersionUID = -2711693270411201590
+1  A: 

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?

Pascal Thivent
A: 

Here is a good link about setting up the EJB3 project for beginner. I used it to explore EJB with Jboss 5.0.1 GA and MyEclipse.

lucentmind