Academic Tutorials



English | French | Portugese | Dutch | Italian
Google

on-line

Haupt Quellenprogramme E-Bücher Downloads Mit uns in Verbindung treten Über uns

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


EJB Beispiel

Previous Next





The Directory Structure

Die folgende Verzeichnisstruktur unter irgendeinem logischem Elternteilverzeichnis, wie c:\ejb _example verursachen. Diese Verzeichnisstruktur ist nur zu den Entwicklung Zwecken; die Entwicklungakten werden in eine Glasakte in einem Moment Reißverschluss zugemacht und entfaltet zu den jboss.

src/
|__client/
| |___com/
| |___examples/
| |___client java files
|__server/
| |__com/
| |___examples/
| |___server (bean) java files
|__shared
| |__com/
| |___examples/
| |___remote and home java files
|
assemble/
|___client and server jars
|
target/
|___client/
| |___com/
| | |___examples/
| | |___client, remote and home java classes
| |___jndi.properties
|___server/
|__com/
| |___examples/
| |___server (bean), remote and home java classes
|___META-INF/
|___ejb-jar.xml
 





The Bean Class

create the bean class as src\server\com\examples\HelloBean.java. This class is a stateless session bean and contains our business logic. In this case it prints out the exciting and always useful "Hello! World".


package com.examples;

import javax.ejb.*;

public class HelloBean implements SessionBean
{
public void ejbCreate() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void ejbRemove() {}
public void setSessionContext(SessionContext sc){}

public String sayHello ()
{
System.out.println ("Someone called sayHello()");
return “Hello! World”;
}
}
 





The Remote Interface

Create the remote interface as src\shared\com\examples\Hello.java. This is the interface that remote clients talk to instead of talking directly to the bean class, HelloBean. Notice that its only method is sayHello(), which is the business method in HelloBean.


package com.examples;

import javax.ejb.*;
import java.rmi.*;

public interface Hello extends EJBObject
{
public String sayHello() throws RemoteException;
}
 




The Home Interface

Create the home interface as src\shared\com\examples\HelloHome.java. This interface will be used to create an instance of the Hello interface when we want to execute the sayHello() business logic.


package com.examples;

import javax.ejb.*;
import java.rmi.*;

public interface Hello extends EJBObject
{
public String sayHello() throws RemoteException;
}
 




The Client

create the client as src\client\com\examples\HelloClient.java. This is the "remote" client that will use our session bean. First, it uses the InitialContext to get a handle to HelloHome. It then uses the HelloHome interface to create hello. hello is a remote interface representing our bean class. After hello is used to execute the business logic (sayHello), the bean is released via the remove method.


package com.examples;

import javax.ejb.*;
import java.rmi.*;
import javax.rmi.*;
import javax.naming.*;

public class HelloClient
{
public static void main (String[] args) throws Exception
{
Context c = new InitialContext();
Object o = c.lookup ("Hello");

HelloHome home =
(HelloHome)PortableRemoteObject.narrow (o,HelloHome.class);
Hello hello = home.create();
System.out.println (hello.sayHello());
hello.remove();
}
}
 




ejb-jar.xml

Create the ejb-jar.xml file in target\server\META-INF. This deployment descriptor contains information that the jboss EJB container needs in order to deploy and run our EJB.


<!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>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>com.examples.HelloHome</home>
<remote>com.examples.Hello</remote>
<ejb-class>com.examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
 




jndi.properties

Create the jndi.properties file in target\client. This file defines properties that are required in order to use JNDI to find EJBs on the network.


java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099




Previous Next

Keywords: EJB Example,jboss ejb example,ejb client example,jboss example,ejb sample,j2ee example,xdoclet example,weblogic example,cmp example,jboss examples,ejb sample code,ejb examples,jboss sample,j2ee sample,sample j2ee application,j2ee examples,web services example,ejb jar xml example,ejb web services,sample weblogic xml,sample ejb jar xml


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
AJAX Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PHP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
XML Web Services Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz

Privacy Policy
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.