Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 23

Simple EJB 3 Application using JBoss and Eclipse. Start Eclipse. Open your Workspace or create a new one.

Create a new EJB Project.

9/16/2

!a"e t#e Project SimpleEjb3Project. $ake sure t#e EJB $o%ule &ersion is '. . C#eck (%% project to an E(). *#is will create a separate Project +or %eploy"ent. Click Next.

9/16/2

We will not use a Client Project +or t#is si"ple e,a"ple. We will not -enerate a .eploy"ent .escriptor. Click Finish.

9/16/2

'

We will create a &ery si"ple application wit# 1 EJB Stateless Session Bean an% create a stan%alone client +or a test. *#e /asic steps are0 1n t#e EJB project o Create a new packa-e na"e% ejbs o Create t#e EJB Bean o Create t#e *est Client

9/16/2

Create a new Packa-e.

!a"e t#e Packa-e ejbs.

9/16/2

Create a new 1nter+ace.

!a"e it SimpleRemote.

9/16/2

(%% t#e +ollowin-.


package ejbs; import javax.ejb.Remote; @Remote public interface SimpleRemote { public String getMessage(); }

9/16/2

Create a new Class.

9/16/2

!a"e t#e Class SimpleBean. 1"ple"ent SimpleRemote.

9/16/2

(%% t#e +ollowin-.


package ejbs; import javax.ejb.Stateless; @Stateless(name="SimpleBean", mappe !ame="ejb"SimpleBean") public class SimpleBean implements SimpleRemote { public String getMessage() { return "#ello $rom %&B '.("; } }

9/16/2

Create a new Packa-e na"e% tests.

9/16/2

11

Create a new Class to test t#e EJB na"e% estEjb.

9/16/2

12

(%% t#e +ollowin-.


package tests; import javax.naming.)ontext; import javax.naming.*nitial)ontext; import ejbs.SimpleRemote; public class +est%jb { ",, , @param args ," public static void main(String-. args) throws %x/eption { String jn i!ame = "ejb"SimpleBean"; )ontext /ontext = new *nitial)ontext(); S0stem.out.println("1oo2ing 3p &!4* !ame " 5 jn i!ame); 6bje/t obje/t = /ontext.loo23p(jn i!ame); S0stem.out.println("1oo23p ret3rne " 5 obje/t); SimpleRemote remote = (SimpleRemote) obje/t; S0stem.out.println(remote.getMessage());

} }

9/16/2

1'

Create a new Source 6ol%er na"e% resources.

9/16/2

12

Create a new +ile na"e% jndi.properties.

9/16/2

13

(%% t#e +ollowin-.


java.naming.$a/tor0.initial=org.jnp.inter$a/es.!aming)ontext7a/tor0 java.naming.$a/tor0.3rl.p2gs=org.jboss.naming8org.jnp.inter$a/es java.naming.provi er.3rl=lo/al9ost8:(;;

9/16/2

16

Create anot#er +ile na"e% log!j.properties.

9/16/2

14

(%% t#e +ollowin-.


< Set root /ategor0 priorit0 to *!76 an log=j.root)ategor0=*!76, )6!S61% its onl0 appen er to )6!S61%.

< )6!S61% is set to be a )onsole>ppen er 3sing a ?attern1a0o3t. log=j.appen er.)6!S61%=org.apa/9e.log=j.)onsole>ppen er log=j.appen er.)6!S61%.+9res9ol =*!76 log=j.appen er.)6!S61%.la0o3t=org.apa/9e.log=j.?attern1a0o3t log=j.appen er.)6!S61%.la0o3t.)onversion?attern=@ AmAn

9/16/2

15

Clean an% Buil% t#e Project.

9/16/2

19

Start t#e Ser&er.

9/16/2

.eploy t#e application.

9/16/2

21

)un t#e *est.

9/16/2

22

7ou s#oul% see t#e +ollowin-.

9/16/2

2'

You might also like