geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: EJB Injection Problem
Date Tue, 02 Sep 2008 17:50:48 GMT

On Sep 2, 2008, at 5:40 AM, Jeremy Cowgar wrote:

> I am having problems using a stand alone program.

Injection only works with jee app clients, typically deployed as a  
client module in an ear.  I wouldn't describe these as "stand alone"

thanks
david jencks


> 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.RemoteInitialContextFactory
> java.naming.provider.url=localhost:4201
>
> Does anyone have any thoughts?
>
> Thank you,
>
> Jeremy
>


Mime
View raw message