users@glassfish.java.net

Problem in accessing EJB from Servlet using Eclipse & Glassfish V2.

From: <glassfish_at_javadesktop.org>
Date: Thu, 02 Oct 2008 23:02:38 PDT

Hi,
I am trying to access the EJB (EJB3.0) from Servlet. I am getting the below error.
I have tried both JNDI lookup and dependency injection. But none are working. I have included the Student.jar for the project StudentEE.war. The archieve is StudentEAR.ear
No error is coming during compilation.
-------------------------------------------------------------------------------------------------------------------
[#|2008-10-02T15:36:46.000+0530|SEVERE|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=19;_ThreadName=Thread-162;_RequestID=bc2e35ce-a23e-4527-985c-2ab18269ef6e;|Class [ Lcom/session/StudentRemote; ] not found. Error while loading [ class control.CreateStudent ]|#]

[#|2008-10-02T15:36:46.000+0530|WARNING|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=19;_ThreadName=Thread-162;_RequestID=bc2e35ce-a23e-4527-985c-2ab18269ef6e;|Error in annotation processing: java.lang.NoClassDefFoundError: Lcom/session/StudentRemote;|#]

[#|2008-10-02T15:36:46.093+0530|INFO|sun-appserver9.1|javax.enterprise.system.tools.deployment|_ThreadID=19;_ThreadName=Thread-162;|deployed with moduleid = StudentEE|#]

[#|2008-10-02T15:37:02.156+0530|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=17;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=dce068e1-2775-4848-9edb-9cf5976609dd;|
java.lang.NullPointerException
        at control.CreateStudent.processRequest(CreateStudent.java:56)
        at control.CreateStudent.doPost(CreateStudent.java:90)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
        at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
        at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
        at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
        at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
        at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
        at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
|#]
-------------------------------------------------------------------------------------------------------------------

The code is as given below.

-------------------------------------------------------------------------------------------------------------------
StudentRemote.java (Remote Interface)

package com.session;

import javax.ejb.Remote;

@Remote
public interface StudentRemote {
public void populate(String firstName, String lastName, int standard);
}
-------------------------------------------------------------------------------------------------------------------
StudentRemoteBean.java (Bean )

package com.session;

import javax.ejb.Stateless;
import com.session.StudentRemote;

public @Stateless class StudentRemoteBean implements StudentRemote {

        public void populate(String firstName, String lastName, int standard) {
                // TODO Auto-generated method stub
                String s=Integer.toString(standard);
                System.out.println("Hi "+firstName+" "+lastName+" "+s);
        }

}

-------------------------------------------------------------------------------------------------------------------
ejb-jar.xml (in Student - ejb project)

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
</ejb-jar>

-------------------------------------------------------------------------------------------------------------------
sun-ejb-jar.xml (in Student - ejb project)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
  <enterprise-beans/>
</sun-ejb-jar>

-------------------------------------------------------------------------------------------------------------------
CreateStudent.java (Servlet in STudentEE)


package control;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.session.StudentRemote;

/**
 * Servlet implementation class for Servlet: CreateStudent
 *
 */
 public class CreateStudent extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   @EJB
   StudentRemote sr;
    /* (non-Java-doc)
         * @see javax.servlet.http.HttpServlet#HttpServlet()
         */
        public CreateStudent() {
                super();
        }
        
        /* (non-Java-doc)
         * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
        }
        
        /* (non-Java-doc)
         * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                String firstName=request.getParameter("fname");
                String lastName=request.getParameter("lname");
                int stnd=new Integer(request.getParameter("stnd"));
                
                try {
                        PrintWriter out=response.getWriter();
                        response.setContentType("text/html");
                        
                        out.println("<html><body bgcolor="+"\""+"black"+"\""+">");
                        out.println("<html><font color="+"\""+"white"+"\""+">");
                        
                        sr.populate(firstName, lastName, stnd);
                        out.println("<h2><b> Successful </b></h2>");
                        out.println("</font></body></html>");
                        out.flush();
                }catch(IOException ioe) {
                        ioe.printStackTrace();
                }
        }
}
-------------------------------------------------------------------------------------------------------------------
index.jsp (in StudentEE)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="white">
<font face="arial" color="green" >

<form method="POST" action="CreateStudent">
<p><b style="COLOR: #ff8040; FONT-SIZE: x-large;">Enter the details of the student</b></p>
<table style="height: 100px; width: 459px; color: green" border="4" bordercolor="black">
<tr>
                <td><b>Enter the first name of the student</b></td>

                <td><input type="text" name="fname" size="10" maxlength="10"></td>
        </tr>
        <tr>
                <td><b>Enter the last name of the student</b></td>

                <td><input type="text" name="lname" size="10" maxlength="10"></td>
        </tr>
        <tr>
                <td><b>Enter the standard</b></td>

                <td><input type="text" name="stnd" size="10" maxlength="10"></td>
        </tr>
        <tr>
                <td><input type="submit" value="Submit"></td>
        </tr>
</table>
</form>

</font>
    </body>
</html>
-------------------------------------------------------------------------------------------------------------------
sun-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
  <context-root>/StudentEE</context-root>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class java code.</description>
    </property>
  </jsp-config>
</sun-web-app>

-------------------------------------------------------------------------------------------------------------------
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StudentEE</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>CreateStudent</display-name>
    <servlet-name>CreateStudent</servlet-name>
    <servlet-class>control.CreateStudent</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CreateStudent</servlet-name>
    <url-pattern>/CreateStudent</url-pattern>
  </servlet-mapping>
</web-app>

-------------------------------------------------------------------------------------------------------------------

Could any body please help me to resolve the problem?

__________
Thanks ,
Rajeev
[Message sent by forum member 'rajeev_tumkur' (rajeev_tumkur)]

http://forums.java.net/jive/thread.jspa?messageID=303093