0

I am developing an application client that needs to access beans remotely on the gf server. From reading I thought I should be able to use injection annotations but this would not work for me. I then switched to using InitialContext looking up the mapped name of my bean but I can't get this to work either. I have looked at a few threads here on this and as far as I can make out all the jars I need should be included and I have added the EJB project to my appCLients path. This does not work from either in Eclipse or by clicking launch from the server admin pages.

My Bean in the EJB project

/**
 * Session Bean implementation class MazeBean
 */
@Stateless(mappedName = "mazes")
@Remote
public class MazeBean
{

The class I am trying to access from (not main which, I think, is why I couldn't use injection)

public class MazeBuilder
{
    private MazeBean mazeBean;  
    Maze maze;

    public MazeBuilder()
    {
        Context ctx;
        try
        {
            ctx = new InitialContext();
            mazeBean = (MazeBean)ctx.lookup("java:comp/env/mazes");
        } catch (NamingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }       
        maze = mazeBean.getMaze(1); (line 31)
        mazeBean.regenerateMaze(maze);
    }

}

The exception I get when running in Eclipse

javax.naming.NamingException: Lookup failed for 'java:comp/env/mazes' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NameNotFoundException: No object bound for java:comp/env/mazes [Root exception is java.lang.NullPointerException]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at mazeBuilder.MazeBuilder.<init>(MazeBuilder.java:23)
    at Main.main(Main.java:16)
Caused by: javax.naming.NameNotFoundException: No object bound for java:comp/env/mazes [Root exception is java.lang.NullPointerException]
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:229)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
    ... 4 more
Caused by: java.lang.NullPointerException
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:159)
    ... 5 more
Exception in thread "main" java.lang.NullPointerException
    at mazeBuilder.MazeBuilder.<init>(MazeBuilder.java:31)
    at Main.main(Main.java:16)

Now it says that there is no object with that name so I am obviously not setting this up correctly. I was under the impression that the annotations are a legal method of definition so the mappedName attribute of my bean should allow me to find it. What else do I need to make the bean discoverable?

Eclipse Kepler, GF4, MySql 5.5.31, EclipseLink 2.5

I have tried both methods in the main also and get the same exception

onesixtyfourth
  • 744
  • 9
  • 30
  • Do I need to configure a JNDI name on the server? – onesixtyfourth Feb 01 '14 at 11:17
  • Take a look at this blog post: http://thegreyblog.blogspot.com/2010/09/ejb-31-global-jndi-access.html – Arek Feb 01 '14 at 11:45
  • I dont have seperate interface defined but I also dont think it should be an issue. Is this correct? – onesixtyfourth Feb 01 '14 at 12:29
  • Using (MazeBean)ctx.lookup("java:global/mazeApp/mazeEJB/mazes"); & I am still getting the NullPointerException. Throughout that blog the auther seems to suggest that it should all work with annotations until the linked one where it seems that I need to use the context. I tried the string above with both name and mappedname in the stateless annotation but I can't get either to work. – onesixtyfourth Feb 01 '14 at 12:56

1 Answers1

0

I have got past this problem now, thanks Ajan, and it was adding gf-client.jar and appserv-rt.jar from the glassfish lib directory after I had corrected the global name.

ps - How do I set a question as solved?

onesixtyfourth
  • 744
  • 9
  • 30