I deployed example ear file in JBoss, Jboss gave class cast exception- portable remote object.
I am using RHEL 4
my profram is like this downloaded from net, example3.ear from roseindia.net. The code is like this
bean:
public class MyTestSessionBean
implements SessionBean
{
public void ejbCreate()
throws
CreateException
{
}
public String SayHello(){
String msg="Hello! I am Session Bean";
System.out.println(msg);
return msg;
}
public void setSessionContext( SessionContext aContext )
throws EJBException
{
}
public void ejbActivate()
throws EJBException
{
}
public void ejbPassivate()
throws EJBException
{
}
public void ejbRemove()
throws EJBException
{
}
}
servlet:
package test.session;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class SessionTestServlet extends HttpServlet {
MyTestSessionHome testSessionBean;
public void init(ServletConfig config) throws ServletException{
//Look up home interface
try {
InitialContext ctx = new InitialContext();
Object objref = ctx.lookup("ejb/test/MyTestSessionBean");
testSessionBean = (MyTestSessionHome)PortableRemoteObject.narrow(objref, MyTestSessionHome.class);
} catch (Exception NamingException) {
NamingException.printStackTrace();
}
}
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
response.setContentType("text/html");
String title = "EJB Example";
out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World Servlet!</title>");
out.println("</head>");
out.println("<body>");
out.println("<p align=\"center\"><font size=\"4\" color=\"#000080\">Servlet Calling Session Bean</font></p>");
try{
MyTestSession beanRemote;
beanRemote = testSessionBean.create();
out.println("<p align=\"center\"> Message from Session Bean is: <b>" + beanRemote.SayHello() + "</b></p>");
beanRemote.remove();
}catch(Exception CreateException){
CreateException.printStackTrace();
}
out.println("<p align=\"center\"><a href=\"javascript:history.back()\">Go to Home</a></p>");
out.println("</body>");
out.println("</html>");
out.close();
}
public void destroy() {
System.out.println("Destroy");
}
}
ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>Example 3</description>
<display-name>Example 3</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session id="test_MyTestSession">
<display-name>My Test Session Bean</display-name>
<ejb-name>test/MyTestSession</ejb-name>
<home>test.session.MyTestSessionHome</home>
<remote>test.session.MyTestSession</remote>
<ejb-class>test.session.MyTestSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
</assembly-descriptor>
</ejb-jar>
jboss.xml:
<jboss>
<enterprise-beans>
<session>
<ejb-name>test/MyTestSession</ejb-name>
<jndi-name>ejb/test/MyTestSessionBean</jndi-name>
</session>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
i have set JBOSS_HOME, jdk path, class path to
JAVA_HOME= /usr/java/jdk1.5.0_11
PATH=/usr/java/jdk1.5.0_11/bin:$PATH
CLASSPATH=/usr/java/jdk1.5.0_11/lib:$CLASSPATH
JBOSS_HOME=/home/servers/java/jboss-4.0.5.GA
when i copy , i am getting exception in Jboss. I am unable to resolve this. Should i set any env varible, or jar should be included.