I was able to fix this. This link helped me to try. What I did was add the "java:module/"
in front to the jndi lookup so that it reads the bean
from module
onwards. That link will help to understand it more clearly. Also note that I removed the /local
at the end. Now I just lookup the bean only. IService
interface
is use by two different beans
without any problem now.
This is how I lookup the bean from Java SE client
.
String jndi = "MyService" // this is a run time parameter. Can be 'MyAnotherService'
IService bean = (IService) initialContext.lookup("java:module/"+jndi+"Bean");
And I did not change any annotation in the bean
class. Because nothing worked for me to change the jndi name. :(
@Local
public interface IService { // interface}
@Stateless
public class MyServiceBean implements IService { // bean 1}
@Stateless
public class MyAnotherServiceBean implements IService { // bean 2}
Now I am not depend on the ear or my ejb jar name. Thanks Gabriel for help!!!