Develop EJB using Eclipse3.0 + Lomboz3.0 + JBoss3.2.3

zhaozj2021-02-16  71

Use Eclipse3.0 LOMBOZ3.0 JBOSS

3.2.3

Development EJB

Ginger

Jjc@ykjt.cn

3. Develop an EJB

Do so much preparation, let's write an example helloworld, select the menu file-new-other, bring the following dialog box:

Figure 5

Choose to select Lomboz J2EE Project in Java-Lomboz J2EE Wizard, then click Next:

Figure 6

Enter a project name in Project Name, then click Next button,

Figure 7

Click the Add External Jars button in Figure 7Librarles tab, add c: /sun/appserver/lib/j2ee.jar, then click Next button,

Figure 8

Click the Add button in the EJB Modules tab, add an EJB Module: HelloWorld, then click Targeted Servers,

Figure 9

Select the JBoss 3.2.x server, click the Add button, and finally click the Finish button, then Package Explorer looks like Figure 10 looks like Figure 10.

Figure 10

At the project name HelloWorldProject, click the right mouse button. Select New in the pop-up menu, pop up the chart 11 dialog,

Figure 11

Select Lomboz EJB CREATION WIZARD, then click Next button,

Figure 12

Package Enter Com.test, Name Enter helloworldejb, EJB Type Selects Stateless Session EJB, then click the Finish button, then Package Explorer looks like Figure 13

Figure 13

Right click on the HelloWorldejbbean and select in the pop-up menu.

Lomboz J2EE

, Then choose

Add Ejb Method,

Pop map

14

Dialog,

Figure 14

Enter public string helloworld () in Method Signture, click the Finish button, find it in the generated code:

Public string helloworld () {

Return NULL;

}

change into:

Public string helloworld () {

Return "Hello World!";

}

HelloWorldejbbean in Package Explorer Click the right mouse button, select Lomboz J2EE in the pop-up menu, then select Add EJB To Module, pop up Figure 15 dialog box.

Figure 15

Select EJB [HelloWorld] and click the OK button. Finding HelloWorld in Package Explorer as shown in Figure 16:

Figure 16

Right click on HelloWorld and select in the pop-up menu.

Lomboz J2EE

, Then choose

Generate EJB CLASSES

If there is no error, this is automatically generated

EJBSRC

Folders, the files inside are also automatically generated.

Again

HelloWorld

Click the right mouse button and select in the pop-up menu.

Lomboz J2EE

, Then choose

Deploy Module

To deploy

EJB MODULE

.

EJB MODULE

After the deployment is complete, let's make a client to call

HelloWorld ()

method.

Select in the file menu

NEW,

Choose

Other,

The dialog box in the pop-up is as shown

11

Disted, choose

Lomboz EJB Test Client Wizard, according to the map

In one

Distance, fill in the corresponding parameters,

Figure 17

Then click the Finish button to generate a HelloWorldClient.java file, edit this file, so that the code looks like the following:

//HelloworldClient.java

/ *

* CREATED ON

2004-7-19

*

* Todo to change the Template for this generated file go to to THERATED FILE Go TO

* WINDOW - Preferences - Java - Code Style - Code Templates

* /

Package com.test;

Import java.rmi.remoteexception;

Import java.util.hashtable;

Import javax.ejb.createException;

Import javax.naming.initialcontext;

Import javax.naming.namingexception;

/ **

* @Author administrator

*

* Todo to change the Template for this generated Type Comment Go To To To To To To To TO

* WINDOW - Preferences - Java - Code Style - Code Templates

* /

Public class helloworldclient {

Private com.test.helloWorldejbhome gethome () throws namingexception {

return (com.test.helloworldejbhome) getContext (). Lookup

com.test.heloworldejbhome.jndi_name);

}

Private InitialContext getContext () throws namingexception {

Hashtable props = new hashtable ();

Props.put (InitialContext.Initial_Context_Factory,

"Org.jnp.interfaces.namingContextFactory");

Props.PUT (InitialContext.Provider_URL, "JNP: //127.0.0.1: 1099");

// this Establishes the security for authorization / authentication

// Props.Put (InitialContext.security_principal, "username");

// Props.Put (InitialContext.security_credentials, "password");

InitialContext InitialContext = New InitialContext (PROPS);

Return INIALCONTEXT;

}

Public void testbean () {

Try {

com.test.helloworldejb mybean = gethome (). CREATE ();

// --------------------------------------

// this is the place you make your caver

//System.out.println (MyBean.callyourthod ());

System.out.println (MyBean.Helloworld ());} catch (remoteexcection e) {

E.PrintStackTrace ();

} catch (createException e) {

E.PrintStackTrace ();

} catch (namingexception e) {

E.PrintStackTrace ();

}

}

Public static void main (String [] args) {

HelloWorldClient Test = new helloworldclient ();

Test.TestBean ();

}

}

Let's run this program, enter the JBoss installation directory D: / jboss-

3.2.3

/ bin, run run.bat to start the server, after the server starts, find HelloWorldClient.java in Package Explorer, right-click on it, select Run in the pop-up menu, select Java Application, if control Output Hello World! Description calls are successful, if there is an exception, then you need to look at this article or email give me Jjc@ykjt.cn.

There is also a problem, someone will ask how to run the client in the command prompt environment?

Need to write a batch file RunhelloWorldClient.bat

Java-ClassPath "D: / Eclipse3 / Workspace / EJBPROJECT / BIN; D: / JBOSS-

3.2.3

/client/concurrent.jar;d:/Jboss-3.2.3/client/gnu-regExp.jar;d:/Jboss-3.2.3/client/jacorb.jar;d:/Jboss-3.2.3/client/ JBossall-client.jar; d: /jboss-3.2.3/client/jboss-client.jar; d: /jboss-3.2.3/client/jboss-common-client.jar; d: /jboss-3.2.3 /client/jbossha-client.jar;d:/Jboss-3.2.3/client/jboss-iiop-client.jar;d:/Jboss-3.2.3/client/jboss-j2ee.jar;d:/JBOSS- 3.2.3 / client / jboss-jaas.jar; d: /jboss-3.2.3/client/jbossjmx-ant.jar; d: /jboss-3.2.3/client/jbossmq-client.jar; D: / boss -3.2.3 / client / jbossmqha.jar; D: /Jboss-3.2.3/client/Jboss-Net-Client.jar; D: /Jboss-3.2.3/client/jbossx-client.jar; D: / JBoss-3.2.3 / client.jar; d: /jboss-3.2.3/client/jcert.jar; d: /jboss-3.2.3/client/jmx-connector-client-factory. JAR; D: /JBOSS-3.2.3/client/jmx-ejb-connector-client.jar; d: /jboss-3.2.3/client/jmx-rmi-connector-client.jar; d: /jboss-3.2 .3 / client / jnet.jar; D: /JBoss-3.2.3/client/jnp-client.jar; d: /jboss-3.2.3/client/jsse.jar; d: /jboss-3.2.3/ Client / log4j.jar "com.test.helloworldclient

Place it in the D: / Eclipse3 / Workspace / HelloWorldProject / bin directory (Copy of COM / TEST), then run, or add the path in the quotation marks in the above batch number in the environment variable ClassPath, then run Java com.test .Heloworldclient

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

New Post(0)