geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Cowgar <jer...@cowgar.com>
Subject EJB Injection Problem
Date Tue, 02 Sep 2008 12:40:48 GMT
I am having problems using a stand alone program. I have the  
following code:

public class Main {
	@EJB
	private GreeterRemote greeter;
	
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		System.out.println(greeter.getGreeting("Jeremy"));
	}

}

greeter is always null. If I provide an initial context and do the  
lookup myself, it works as expected:

public class Main {
	private GreeterRemote greeter;
	
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		super();

		try {
			InitialContext ic = new InitialContext();
			greeter = (GreeterRemote) ic.lookup("GreeterRemote");
			System.out.println(greeter.getGreeting("Jeremy"));
		} catch (NamingException e) {
			e.printStackTrace();
		}
		
	}

}

For the InitialContext() one to work, I have supplied a  
jndi.properties file:

java.naming.factory.initial=org.openejb.client.RemoteInitialContextFacto 
ry
java.naming.provider.url=localhost:4201

Does anyone have any thoughts?

Thank you,

Jeremy


Mime
View raw message