[jboss-user] [EJB 3.0] - Re: JNDI Issue - Deploying EJB3 using Eclipse to JBoss 5

yetti do-not-reply at jboss.com
Mon Apr 6 15:50:24 EDT 2009

Okay, I'm about to drink a pint of windshield wiper fluid. If Peter or anyone else can help me, I'm forever grateful.

I have created a new standard Java project, named com.acmeco.serverapp.ftp.client, that sits next to the EJB3 app in my Eclipse workspace.

I have created a jndi.properties file in the build path that has the data Peter suggested (even though I'm already hardcoding this info in the class itself below).

I have created a new class in the default package called HelloClientPOJO.java. Here is the code:

import javax.naming.InitialContext;
  | import javax.naming.Context;
  | import javax.naming.NamingException;
  | import java.util.Properties;
  | import javax.rmi.PortableRemoteObject;
  | import com.acmeco.serverapp.ftp.ejb3.*;
  | public class HelloClientPOJO {
  | 	FTPBean _ftpbean;
  | 	public HelloClientPOJO(){
  | 		try{
  | 			Context jndiContext = getInitialContext();
  | 			Object ref = jndiContext.lookup("com.acmeco.serverapp.ftp.ejb3.FTPBeanRemote");
  | 			_ftpbean = (FTPBean)ref;
  | 		}catch (javax.naming.NamingException ne){
  | 			//nothing
  | 		}
  | 	}
  | 	protected void sayHello() {
  | 		_ftpbean.doWork();
  | 	}
  | 	public static void main(String [] args)
  | 	{
  | 		HelloClientPOJO helloClient= new HelloClientPOJO();
  | 		helloClient.sayHello();
  | 	}
  | 	// developed for JBoss only. this is vender dependency
  | 	public static Context getInitialContext( ) throws javax.naming.NamingException {
  | 		Properties p = new Properties( );
  | 		p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  | 		p.put(Context.URL_PKG_PREFIXES, " org.jboss.naming:org.jnp.interfaces");
  | 		p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
  | 		return new javax.naming.InitialContext(p);
  | 	}
  | }

Here is the error on the console when the POJO app runs:
Exception in thread "main" java.lang.NullPointerException
	at HelloClientPOJO.sayHello(HelloClientPOJO.java:24)
	at HelloClientPOJO.main(HelloClientPOJO.java:30)

I got this from this URL/tutorial:

Neither the server nor the bean(s) have been changed, so my JBoss startup/deployment log and JNDI info is all the same as before. What am I doing wrong? What do I need to put into the content lookup to find the bean?

Please help! Once I get this working, I am going to write the world's most idiot proof Hello World for JBoss 5/EJB 3/Eclipse. I know a LOT of other people have/had problems with these issues. I want to end the confusion once and for all.


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4223795#4223795

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4223795

More information about the jboss-user mailing list