Its easy to implement it in NetBeans.(using insert code and calling enterprise bean).
I am trying it to do it in Eclipse.(Was able to do it using Dependency Injection. @EJB annotation and placing the jar file of the bean in the WEB-INF/lib folder of the Web Content.)
But i am not able to do it using the JNDI way as mentioned in the previous post.
Here are my code snippets,
local bean interface
<CODE>
package com.rohit.ejbs;
import javax.ejb.Local;
@Local
public interface TestSessionBeanLocal {
String beanMethod();
}
</CODE>
Stateless session bean
<CODE>
package com.rohit.ejbs;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Stateless(name="TestSession")
@Local(TestSessionBeanLocal.class)
public class TestSessionBean implements TestSessionBeanLocal{
@Override
public String beanMethod() {
return "Testing my first EJB in Eclipse using JBoss AS 7.1";
}
}
</CODE>
And the GET method code snippet of the servlet,
<CODE>
Context initialContext = new InitialContext();
TestSessionBeanLocal testSessionBeanLocal= (TestSessionBeanLocal) initialContext.lookup("TestEJB/TestSessionBean/local");
out.println(testSessionBeanLocal.beanMethod());
</CODE>
Actually was just following this -
http://www.half-wit4u.blogspot.in/2012/02/ejb3-simplified-approach.html