[转] JBoss 4.0 EJB deployment

xiaoxiao2021-03-06  51

JBoss 4.0 EJB HelloWorld Development Environment: Java SDK 1.4.2, JBoss 4.0, Windows 2003

Developing SessionBean EJB minus also requires three Class, Remote Interface, Home Interface, and Bean Implementation (Bean behavior).

1. Remote interface is used to reveal some of the way EJB.

package helloWorld; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface RemoteHello extends EJBObject {public String HelloEcho (String inputString) throws RemoteException;} 2.home interface is used to specify how to implement a remote interface to create the bean Import java.io.serializable; import java.rmi.remoteException; import javax.ejb.createException; import javax.ejb.ejbhome; Public Interface Homehello Extends Ejbhome

{Remotehello Create () THROWS RemoteException, CreateException;

3.Bean Implementation is an implementation of the method, which is specified in the above two INTERFACEs.

Package helloworld;

Import java.rmi.remoteexception;

Import javax.ejb.sessionbean;

Import javax.ejb.sessionContext;

Public class hellobean implements sessionbean {

Public String Helloecho (String InputString) {

System.out.Println ("Someone Called 'Hello Echo Successed!');

Return "*********" InputString "*********";

/ ** EMPTY METHOD BODY * /

Public void ejbcreate () {

System.out.println ("EJB 4 IS CREANG! ...");

/ ** every ejbcreate () Method Always Needs a corresponding ejbpostcreate () Method with exactly the Same Parameter type. * /

Public void ejbpostcreate () {}

/ ** EMPTY METHOD BODY * /

Public void ejbremove () {

System.out.println ("EJB 4 IS Removing! ...");

/ ** EMPTY METHOD BODY * /

Public void ejbactivate () {

System.out.println ("EJB 4 IS Activating! ...");

/ ** EMPTY METHOD BODY * /

Public void ejbpassiVate ()

{}

/ ** EMPTY METHOD BODY * /

Public void setsessionContext (sessioncontext sc) {}

}

Deploy JAR

These classes must be packaged in a JAR file, and the JAR file contains the level of directory structure and packages. In this example, these classes is in the package helloworld so they need to be the directory HelloWorld /.

Deployment Release Descriptor EJB-JAR.XML and JBOSS.XML Requires a directory called meta-infers before the JAR document is created, which is the storage deployment release descriptor (generally called EJB-jar.xml).

Neosue HelloWorld Sample Application HelloWorld EJB HelloWorld HelloWorld.homehello <... - Remote Interface -> HelloWorld.Remotehello HelloWorld.Hellobean stateless bean

Jboss.xml

HelloWorld HelloWorld / Hello Although there is the above application and JNDI Name, you also need a JNDI.Properties file once deployed on the JBoss server, to tell the call to the client request to request Where to initialize JNDI Naming Service.

test program:

Import javax.naming.context;

Import javax.naming.initialcontext; import javax.rmi.portableremoteObject;

Import helloworld. *;

Public class mytest {

Public static void main (String [] args) {

Try {context ctx = new initialContext ();

Object ref = ctx.lookup ("HelloWorld / Hello");

HOMEHELLO HOME = (HOMEHELLO) PortableRemoteObject.Narrow (Ref, Homehello.class);

RemoteHello User = home.create (); system.out.println (user.helloecho ("so easy!");

} catch (exception e) {

E.PrintStackTrace ();

}

}

}

JBoss EJB Deployment Steps to establish Remote Interface -> Home Interface -> And Bean Implementation -> EJB-JAR.XML -> JBoss.xml - Package (Package [JAR CVF PackageName.jar.]) -> Copy To the JBoss Deploy directory. --------------------------------------------- ------------ Original url http://blog.blogchina.com/refer.159508.html ------------------- ------------------------------------ Added instructions as follows: OS: Windows 2000; JDK: 1.5.0RC ; JBoss: 4.0 HelloWorld.jar | --meta-inf | | --jboss.xml | | --EJB-JAR.XML | | --MANIFEST.MF (Automatic Generation) | --helloworld | --Remotehello.class | --jndi.properties | - HOMEHELLO.CLASS | --HELLOBEAN.CLASS Among them, the test file Mytest.class is copied with a directory. JNDI.Properties is as follows: java.naming.factory.initial = Org.jnp.interfaces.namingContextFactory java.naming.provider.ur = localhost: 1099 java.naming.factory.URL.PKGS = Org.jboss.naming: org.jnp.interfaces

转载请注明原文地址:https://www.9cbs.com/read-82098.html

New Post(0)