EJB Learning (ii)--Creating the first EJB project with Eclipse+jboss

Source: Internet
Author: User
Tags jboss jboss server

1. Environment configuration


· Eclipse Luna Service Release 1 (4.4.1)

· JBOSS as 5.0

· Java 1.8.0_25


2. Create an EJB project


Click File → New → EJB project, and fill in the project name as follows:

Then click Next → Finish;


Select the Ejbmodule folder under the EJB project and right-click → New→ Session bean (EJB 3.X) to create a session bean.



Hellowrold Interface:

Package Com.tgb.ejb;public interface HelloWorld {public string SayHello (string name);}

Hellowroldbean Implementation class:

Package Com.tgb.ejb;import javax.ejb.remote;import javax.ejb.stateless;/** * Session Bean Implementation class HelloWorld */@Stateless @remote ({helloworld.class}) public class Helloworldbean implements HelloWorld {@Overridepublic String SayHello (string name) {return name+ "Welcome to use ejb3.0~~";}}

3. Deployment


There are two ways of deploying:


① released in Eclipse

In the previously created server, right-click Add and Remove, and then start the project.


② is packaged and then deployed to the specified server

On the project right → Export→ EJB JAR file, select the JBOSS Server deployment directory: Jboss_home/server/defau Lt/deploy, complete.


4. Create a client


①  Click File→new→other ... →java Project



② Add a reference to the above Ejb_01.jar and the JBoss Client jar package ( $JBOSS _home/clent/jbossall-clent.jar), add to the classpath path.



③ Write the client test class, the code is as follows

Package Com.tgb.ejb.client;import Javax.naming.initialcontext;import Javax.naming.namingexception;import Com.tgb.ejb.helloworld;public class Client {public static void main (string[] args) throws Namingexception { InitialContext InitialContext = new InitialContext (); HelloWorld EJB = (HelloWorld) initialcontext.lookup ("Helloworldbean/remote"); String name = Ejb.sayhello ("Zhoujiang"); SYSTEM.OUT.PRINTLN (name);}}

5. Running the client


Start JBoss first;

Run the client code to prove our remote call succeeded.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

EJB Learning (ii)--Creating the first EJB project with Eclipse+jboss

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.