2
votes

I'm using EJB3, GlassFish 3.0.1 and eclipse helios

I have a remote EJB

@Stateless (mappedName="TestBean")
public class TestBean implements TestBeanRemote {
public int add(int a, int b){
return a+b;
}
}

And the Remote Interface

@Remote
public interface TestBeanRemote {
    public int add(int a, int b);
}

application.xml

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <application-name>ear.proj</application-name>
  <display-name>ear.proj</display-name>
  <module>
    <web>
      <web-uri>war.proj</web-uri>
      <context-root>/war</context-root>
    </web>
  </module>
  <module>
    <ejb>ejb.proj.jar</ejb>
  </module>
</application>

I have an empty sun-ejb-jar.xml and I did not define ejb-jar.xml as I read that it's optional since EJB3 I'm putting my EJB in the EAR along with the WEB

I'm trying to call this EJB in a POJO class

InitialContext ic = new InitialContext();
ic.lookup("java:global/ear.proj/ejb.proj/TestBean");

I get the following exception javax.naming.NamingException: Lookup failed for java:global/ear.proj/ejb.proj/TestBean' in SerialContext [Root exception is javax.naming.NameNotFoundException: ear.proj]

I guess that the problem is in the EJB setup in my EAR as it's said in the GlassFish EJB FAQ that Each portable global JNDI name is printed out to the server.log during deployment while I can not find any portable keyword in the log

Instead I can see the following INFO: Cannot find module ejb.proj.ejb.jar in application bundle

Is there something I'm missing?

2
can you explain more about your Pojo class? Since your code above uses EJB3, is there a particular reason you aren't using EJB3 injection? @EJB TestBeanRemote TestBeanRemote;Jonathan S. Fisher

2 Answers

1
votes

Make sure if you are deploying EJB project, you are notified about this in server.log

INFO: Portable JNDI names for EJB ${EJB_Name}: 
INFO: Glassfish-specific (Non-portable) JNDI names for EJB ${EJB_Name}:

There you will see context paths.

PS in order to see those logs, depending on configuratoin you may need to change logger settings or even you will be forces to browse through server.log file on server.

0
votes

Try to use:

ic.lookup("java:global/*classesdirectory*/TestBean");

where classesdirectory = the directory which contains the classes(TestBean.class) in your project tree in Eclipse.

In Netbeans you can try

ic.lookup("java:global/classes/TestBean");

because the compile classe (even package and subpackage ar)