In this section we will write the deployment descriptor for the session bean. We need the deployment descriptor for application (application.xml), ejb deployment descriptors (ejb-jar.xml and weblogic-ejb-jar.xml) and web.xml files.
Application Deployment descriptor:
We need the following application deployment descriptor to create our ear file (example.ear).
<?xml version="1.0" encoding="ISO-8859-1"?> Inc.//DTD J2EE Application 1.2//EN' 'http://java.sun.com /j2ee/dtds/application_1_2.dtd'> |
EJB Deployment descriptor:
To create example.jar file we need ejb-jar.xml and weblogic-ejb-jar.xml files. Here is the code for ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?> Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> |
The name of our session bean is TestSessionBean, we will call this bean from servlet (as described in the next page).
The code for weblogic specific ejb deployment descriptor(weblogic-ejb-jar.xml) is as follows:
<?xml version="1.0" encoding="UTF-8"?> //DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers /wls600/dtd/weblogic-ejb-jar.dtd"> |
The JNDI name for our Staeless Session bean is TestSessionBean. We will use this JNDI name to lookup the Bean and call it from Servlet.
Web.xml file for war file:
web.xml file describes the example.war file, which is our web application. Here is the code of web.xml file:
| <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app > <distributable/> <servlet> <servlet-name>sessionTest</servlet-name> <display-name>Session Test Servlet</display-name> <servlet-class>net.roseindia.web.servlets.SessionTestServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sessionTest</servlet-name> <url-pattern>/SessionServlet</url-pattern> </servlet-mapping> </web-app> |
Note that in the above web.xml file we have define a servlet named sessionTest. We will use this servlet to call the Staleless Session Bean. Here is the code of servlet used to call session bean:
|
|
In the next section I will show you how to deploy and test the application.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Writing Deployment Descriptor of Stateless Session Bean
Post your Comment