SlideShare a Scribd company logo
Java Training Center
(No 1 in Training & Placement)
1
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
RMI
(Remote Method Invocation)
1. RMI is distributed technology, which is first attempt of SUN to provide a
solution to distributed programming. RMI use socket. A socket is a transport
mechanism.
2. No extra software is required for developing a distributed application using
RMI other than JDK.
 RMI provides a way for a java program on one machine to communicate with
object residing in different JVM.
 The important part of RMI architecture are the Stubclass object serialization
and Skelton class.
 RMI uses a layered architecture where each of layers can be enhanced without
affected the other layers.
=:-Developing First RMI application-:=
Server Side Steps:-
1. Define a Business Service Interface (B.S.I.).
a. Your Business Service interface has to extends java.rmi.Remote interface.
b. Each Method inside the Business interface has to throw
java.rmi.RemoteException.
2. Provide the implementation class for Business Service Interface.
a. Business Services implements class has to extends “UnicastRemoteObject”
if not extend then implement class is responsible for correct
implementation of hashCode(), equals(), toString().
b. B.S.I. class has to implement Business Interface.
3. Create the Business Service Implement Service Implementation class object.
4. Bind the B.S.I. class object inside RMI registry or JNDI registry.
Java Training Center
(No 1 in Training & Placement)
2
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps in Eclipse :-
1. Create a java Project with the name RMIServer.
2. Create package com.jtcindia.rmi
3. Write the following three files in your package.
a. AccountService.java (interface)
b. AccountServiceImpl.java
c. Server.java (for binding object)
If you have more than one Business class for other purpose than that class
object will create in server.java also.
Client Side Steps :-
1. Locate and get the registry reference.
2. Look Up the registry and get the required remote interface stub.
3. Invoke any required business operation on remote Business stub.
1. Create a java Project called RMI.
2. Create a package java.jtcindia.rmi;
3. Write the following in the Package.
a. Client.java
b. AccountServices.java(copy from the server)
Way to create jar file :-
D:/test> Jar cvf jtc.jar com
(Here AccountServices.class file change to jar file)
Java Training Center
(No 1 in Training & Placement)
3
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
File Required:-
1. Package com.jtcindia.rmi;
Import java.rmi.Remote;
Import java.rmi.RemoteException;
Public interface AccountService extends Remote{
Public double getBal(int accno) throws RemoteException;
}
2. AccountServiceImpl.java
packagecom.jtcindia.rmi;
importjava.rmi.*;
importjava.rmi.server.UnicastRemoteObject;
publicclassAccountServiceImplextendsUnicastRemoteObject
implementsAccountService {
publicAccountServiceImpl() throwsRemoteException {
super();
}
publicdouble getBal(int accno) throws
RemoteException{
System.out.println("getBal() with accno :
"+accno);
return 9999.99;
}}
RemoteException :-This is declare as an interface because in this
there are so many private data available. You have interact with
their subclass method also to avoid data duplication
Java Training Center
(No 1 in Training & Placement)
4
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
3. Server.java :-
packagecom.jtcindia.rmi;
importjava.rmi.registry.LocateRegistry;
importjava.rmi.registry.Registry;
public class Server {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.createRegistry(6789);
AccountServiceasi = new AccountServiceImpl();
reg.bind("ASI", asi);
System.out.println("Server is Running");
} catch (Exception e) {
e.printStackTrace();
}
}
}
4. Client.java :-
packagecom.jtcindia.rmi;
importjava.rmi.registry.LocateRegistry;
importjava.rmi.registry.Registry;
1. Here we need to write a default constructor which throws
RemoteException because in super class UnicastRemoteObject there
is a default constructor without throws ServerException.
2. A remote object is one whose method can be invoke from another
JVM.
Java Training Center
(No 1 in Training & Placement)
5
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
public class Client {
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.getRegistry("localhost", 6789);
AccountService as = (AccountService) reg.lookup("ASI");
doublebal = as.getBal(1);
System.out.println(bal);
bal = as.getBal(2);
System.out.println(bal);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Binding the instance
of the remote object
to the RMI registry.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
6
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
=: EJB2/EJB :=
For Developing any Enterprise Edition you need mainly three types
of services.
 EJB is a remote, distributed multi-tier system. An EJB
application server provide mainly services like transaction
management, Security Management, Object Package which
simplifies the programming effect.
 For any Enterprise Edition development you need these Low
Level Services Commonly which you can get freely from EJB.
 High level Service is nothing but your application code business
logic which will change from Enterprise edition to enterprise
edition.
IMP -: To run RMI application you need “JDK” where to run EJB
application you need “application server”.
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
7
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
 Following are various Application servers available
1. JBOSS(“Red Hat” Linux)
2. Web Logic(“BEA”, Oracle Company)
3. Web sphere(IBM)
Steps to develop and run EJB 2.0 application with JBOSS 4.0
Java Training Center
(No 1 in Training & Placement)
8
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Steps to install JBOSS 4.0 :-
1. Click on installer called jems-installer-1.2.0 CRI.jar which is
available in JBOSS-4.0.
2. Select English and OK.
3. Click on next.
4. Click on next.
5. Accept license agreement and next.
6. Provide the location of installation E:/Jboss 4.0.5
7. Click OK on popup.
8. Select the profile all and click on next.
9. Click on next.
10.Provide the server name jtcindia and next.
11. Configure the default and click next.
12. Click next.
13. Provide admin username and password only and click on
next.
14. Click on next.
15. Click on done.
After installing successfully you can see the directory :-
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
9
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
-: Steps to integrate JBOSS 4.0 with MyEclipse :-
1. Click on window  Preferences
2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x
Integrate means only enable the Plugin.
In “Eclipse” you have to download all the plugin and then
enable if.
3. Select Enable
jBoss home directory: E:/jboss-4.0.5
Server name: jtcindia
Optional program argu:
Optional shutdown arg: -shutdown
4. Expend the JBOSS 4.x
Java Training Center
(No 1 in Training & Placement)
10
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
JDK
Launch
Paths and select the JDK option. And do the following to
add the JDK.
a. Click on add button.
b. Click on Apply.
5. Select the “Launch” under JBOSS 4.x… Run mode and click
Apply.
6. Click on OK of Preference window.
a. By default Port no: 8080 because it take default of
tomcat which is running on 8080.
b. Change that Port no:- if get any error like JVM_8080
i.e. lifecycleException.
-: Stating JBOSS :-
 Change the Port number: 5555.
 Start the JBOSS from myEclipse.
 Open the browser and type http://localhost:5555/imx-console/
 Enter username & password on popup window.
-: Creating EJB Project in myEclipse :-
1. File new  “EJB Project”
Project name: - E2Hello4JB and select J2EE1.4-EJB2.1 and finish.
2. You can see the following directory structure.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
11
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file
from DTD  select category.
To deployselect the Project name and gotodeploy(8th
) Icon. Select
Project E2Hello4JB add to your application server jBoss.
-//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0
--: Create client Project for EJB :-
1. Create a “Java Project” E2client4JB.
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
12
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
Example:-
File required:-
1. HelloRemote.java
2. HelloBean.java
3. HelloHome.java
4. Ejb-jar.xml
5. Jboss.xml
6. HelloClient.java
Java Training Center
(No 1 in Training & Placement)
13
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
1. HelloHome.java
package com.jtcindia.ejb2;
importjava.rmi.*;
importjavax.ejb.*;
publicinterfaceHelloHomeextendsEJBHome{
publicHelloRemote create() throws createException,
RemoteException;
}
2. HelloRemote.java
package com.jtcindia.ejb2;
importjava.rmi.*;
importjavax.ejb.EJBObject;
publicinterfaceHelloRemoteextendsEJBObject{
public String getMessage(String name)
throwsRemoteException;
}
3. HelloBean.java
package com.jtcindia.ejb2;
importjavax.ejb.*;
publicclassHelloBeanextendsSessionBean{
SessionContentsc=null;
Public void setSessionContent(SessionContentsc){
System.out.println("setSesssionContent");
this.sc=sc;
Java Training Center
(No 1 in Training & Placement)
14
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
}
Public void ejbActivate(){
System.out.println("ejbActivate");
}
publicvoidejbPassivate(){
System.out.println("ejbPassivate()");
}
publicvoidejbRemove(){
System.out.println("ejbReamove");
}
publicvoidejbCreate(){
System.out.println("ejbCreate()");
}
publicStringgetMessage(String name){
String msg="Hi"+name+"welcome to JTC EJB with
JBOSS";
System.out.println(msg);
returnmsg;
}
}
4. HelloClient.java
package com.jtcindia.ejb2;
importjava.util.*;
importjavax.naming.*;
public classHelloClient {
publicstaticvoid main(String[] args) {
try{
Properties p=newProperties();
Java Training Center
(No 1 in Training & Placement)
15
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
p.put("java.naming.factory.initial","org.jnp.interf
aces.NamingContentFactory");
p.put("java.naming.provider.url","localhost:1099");
p.put("java.naming.factory.url.package","org.jboss.
naming");
Contentctx=newInitialContext(p);
Object o=ctx.lookup("JTCHelloHomeJNDI");
HelloHomehh=(HelloHome)o;
HelloRemotehr=hh.create();
String msg=hr.getMessage("Som");
System.out.println(msg);
msg=hr.getMessage("Som");
System.out.println(msg);
}catch(Exception e){
e.printStackTrace();
}
}
}
5. ejb-jar.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEejb-jarPUBLIC"-//Sun MicroSystem,INC.//DTD
Enterprise JavaBean
2.0//EN","http://Java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HelloEJB</ejb-name>
<home>com.jtcindia.ejb2.HelloHome</home>
<remote>com.jtcindia.ejb2.HelloRemote</remote>
Java Training Center
(No 1 in Training & Placement)
16
RMI Part 1
Author: SomPrakashRai www.jtcindia.org
Copyright©JTC
<ejb-class>com.jtcindia.ejb2.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<trasaction-type>Container</trasaction-type>
</session>
</enterprise-beans>
</ejb-jar>
6. jboss.xml
<jboss>
<enterprise-beans>
<session>
<ejb-name>HelloEJB</ejb-name>
<jndi-name>JTCHelloHomeJNDI</jndi-name>
</session>
</enterprise-beans>
</jboss>

More Related Content

PDF
Core java introduction
PDF
Java script Examples by Som
PDF
Jdbc Complete Notes by Java Training Center (Som Sir)
PDF
Bea weblogic job_interview_preparation_guide
PDF
Java interview questions
PDF
Java j2ee interview_questions
ODP
Java 9 Features
Core java introduction
Java script Examples by Som
Jdbc Complete Notes by Java Training Center (Som Sir)
Bea weblogic job_interview_preparation_guide
Java interview questions
Java j2ee interview_questions
Java 9 Features

What's hot (20)

PDF
Core java interview questions
PDF
Hibernate Advance Interview Questions
PPT
Java interview-questions-and-answers
PDF
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
PPTX
Dev labs alliance top 20 basic java interview question for sdet
PDF
PDF
Java 10 New Features
DOCX
Hibernate notes
PDF
50+ java interview questions
PPTX
[AnDevCon 2016] Mutation Testing for Android
PDF
Corejava ratan
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
DOCX
Hibernate3 q&a
PPTX
Technical Interview
PDF
DataFX 8 (JavaOne 2014)
PDF
Best interview questions
PDF
Certified Core Java Developer
PPTX
Core java
PPTX
Apache Cordova In Action
PPTX
Spring andspringboot training
Core java interview questions
Hibernate Advance Interview Questions
Java interview-questions-and-answers
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Dev labs alliance top 20 basic java interview question for sdet
Java 10 New Features
Hibernate notes
50+ java interview questions
[AnDevCon 2016] Mutation Testing for Android
Corejava ratan
Efficient JavaScript Unit Testing, JavaOne China 2013
Hibernate3 q&a
Technical Interview
DataFX 8 (JavaOne 2014)
Best interview questions
Certified Core Java Developer
Core java
Apache Cordova In Action
Spring andspringboot training
Ad

Similar to EJB Part-1 (20)

DOCX
EJB.docx
PPTX
Java RMI Presentation
PPTX
Java RMI
PPT
Java RMI
PDF
Introduction to Remote Method Invocation (RMI)
PPTX
Introduction To Rmi
PDF
Remote Method Invocation in JAVA
PPTX
PDF
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
DOCX
ADB Lab Manual.docx
DOCX
Remote Method Invocation
DOCX
remote method invocation
PDF
Java rmi tutorial
DOCX
Java interview questions for freshers
PPTX
PDF
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
PPTX
Rmi architecture
PPT
Session 1 Tp1
PDF
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
PPTX
The Latest in Enterprise JavaBeans Technology
EJB.docx
Java RMI Presentation
Java RMI
Java RMI
Introduction to Remote Method Invocation (RMI)
Introduction To Rmi
Remote Method Invocation in JAVA
JavaRMI, JAVA RPC , INTRO , DESCRIPTION , EXPLAINED.pdf
ADB Lab Manual.docx
Remote Method Invocation
remote method invocation
Java rmi tutorial
Java interview questions for freshers
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
Rmi architecture
Session 1 Tp1
java TM rmi The Remote Method Invocation Guide 1st Edition Esmond Pitt
The Latest in Enterprise JavaBeans Technology
Ad

Recently uploaded (20)

PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Geodesy 1.pptx...............................................
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
composite construction of structures.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
CYBER-CRIMES AND SECURITY A guide to understanding
Mechanical Engineering MATERIALS Selection
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Geodesy 1.pptx...............................................
UNIT 4 Total Quality Management .pptx
Digital Logic Computer Design lecture notes
UNIT-1 - COAL BASED THERMAL POWER PLANTS
bas. eng. economics group 4 presentation 1.pptx
R24 SURVEYING LAB MANUAL for civil enggi
CH1 Production IntroductoryConcepts.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Sustainable Sites - Green Building Construction
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
composite construction of structures.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd

EJB Part-1

  • 1. Java Training Center (No 1 in Training & Placement) 1 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC RMI (Remote Method Invocation) 1. RMI is distributed technology, which is first attempt of SUN to provide a solution to distributed programming. RMI use socket. A socket is a transport mechanism. 2. No extra software is required for developing a distributed application using RMI other than JDK.  RMI provides a way for a java program on one machine to communicate with object residing in different JVM.  The important part of RMI architecture are the Stubclass object serialization and Skelton class.  RMI uses a layered architecture where each of layers can be enhanced without affected the other layers. =:-Developing First RMI application-:= Server Side Steps:- 1. Define a Business Service Interface (B.S.I.). a. Your Business Service interface has to extends java.rmi.Remote interface. b. Each Method inside the Business interface has to throw java.rmi.RemoteException. 2. Provide the implementation class for Business Service Interface. a. Business Services implements class has to extends “UnicastRemoteObject” if not extend then implement class is responsible for correct implementation of hashCode(), equals(), toString(). b. B.S.I. class has to implement Business Interface. 3. Create the Business Service Implement Service Implementation class object. 4. Bind the B.S.I. class object inside RMI registry or JNDI registry.
  • 2. Java Training Center (No 1 in Training & Placement) 2 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps in Eclipse :- 1. Create a java Project with the name RMIServer. 2. Create package com.jtcindia.rmi 3. Write the following three files in your package. a. AccountService.java (interface) b. AccountServiceImpl.java c. Server.java (for binding object) If you have more than one Business class for other purpose than that class object will create in server.java also. Client Side Steps :- 1. Locate and get the registry reference. 2. Look Up the registry and get the required remote interface stub. 3. Invoke any required business operation on remote Business stub. 1. Create a java Project called RMI. 2. Create a package java.jtcindia.rmi; 3. Write the following in the Package. a. Client.java b. AccountServices.java(copy from the server) Way to create jar file :- D:/test> Jar cvf jtc.jar com (Here AccountServices.class file change to jar file)
  • 3. Java Training Center (No 1 in Training & Placement) 3 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC File Required:- 1. Package com.jtcindia.rmi; Import java.rmi.Remote; Import java.rmi.RemoteException; Public interface AccountService extends Remote{ Public double getBal(int accno) throws RemoteException; } 2. AccountServiceImpl.java packagecom.jtcindia.rmi; importjava.rmi.*; importjava.rmi.server.UnicastRemoteObject; publicclassAccountServiceImplextendsUnicastRemoteObject implementsAccountService { publicAccountServiceImpl() throwsRemoteException { super(); } publicdouble getBal(int accno) throws RemoteException{ System.out.println("getBal() with accno : "+accno); return 9999.99; }} RemoteException :-This is declare as an interface because in this there are so many private data available. You have interact with their subclass method also to avoid data duplication
  • 4. Java Training Center (No 1 in Training & Placement) 4 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC 3. Server.java :- packagecom.jtcindia.rmi; importjava.rmi.registry.LocateRegistry; importjava.rmi.registry.Registry; public class Server { public static void main(String[] args) { try { Registry reg = LocateRegistry.createRegistry(6789); AccountServiceasi = new AccountServiceImpl(); reg.bind("ASI", asi); System.out.println("Server is Running"); } catch (Exception e) { e.printStackTrace(); } } } 4. Client.java :- packagecom.jtcindia.rmi; importjava.rmi.registry.LocateRegistry; importjava.rmi.registry.Registry; 1. Here we need to write a default constructor which throws RemoteException because in super class UnicastRemoteObject there is a default constructor without throws ServerException. 2. A remote object is one whose method can be invoke from another JVM.
  • 5. Java Training Center (No 1 in Training & Placement) 5 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC public class Client { public static void main(String[] args) { try { Registry reg = LocateRegistry.getRegistry("localhost", 6789); AccountService as = (AccountService) reg.lookup("ASI"); doublebal = as.getBal(1); System.out.println(bal); bal = as.getBal(2); System.out.println(bal); } catch (Exception e) { e.printStackTrace(); } } } Binding the instance of the remote object to the RMI registry.
  • 6. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”. Java Training Center (No 1 in Training & Placement) 6 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC =: EJB2/EJB := For Developing any Enterprise Edition you need mainly three types of services.  EJB is a remote, distributed multi-tier system. An EJB application server provide mainly services like transaction management, Security Management, Object Package which simplifies the programming effect.  For any Enterprise Edition development you need these Low Level Services Commonly which you can get freely from EJB.  High level Service is nothing but your application code business logic which will change from Enterprise edition to enterprise edition. IMP -: To run RMI application you need “JDK” where to run EJB application you need “application server”.
  • 7. Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0 Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0 Java Training Center (No 1 in Training & Placement) 7 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC  Following are various Application servers available 1. JBOSS(“Red Hat” Linux) 2. Web Logic(“BEA”, Oracle Company) 3. Web sphere(IBM) Steps to develop and run EJB 2.0 application with JBOSS 4.0
  • 8. Java Training Center (No 1 in Training & Placement) 8 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Steps to install JBOSS 4.0 :- 1. Click on installer called jems-installer-1.2.0 CRI.jar which is available in JBOSS-4.0. 2. Select English and OK. 3. Click on next. 4. Click on next. 5. Accept license agreement and next. 6. Provide the location of installation E:/Jboss 4.0.5 7. Click OK on popup. 8. Select the profile all and click on next. 9. Click on next. 10.Provide the server name jtcindia and next. 11. Configure the default and click next. 12. Click next. 13. Provide admin username and password only and click on next. 14. Click on next. 15. Click on done. After installing successfully you can see the directory :-
  • 9. Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x Java Training Center (No 1 in Training & Placement) 9 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC -: Steps to integrate JBOSS 4.0 with MyEclipse :- 1. Click on window  Preferences 2. My Eclipse workbench  Servers  JBOSS JBOSS 4.x Integrate means only enable the Plugin. In “Eclipse” you have to download all the plugin and then enable if. 3. Select Enable jBoss home directory: E:/jboss-4.0.5 Server name: jtcindia Optional program argu: Optional shutdown arg: -shutdown 4. Expend the JBOSS 4.x
  • 10. Java Training Center (No 1 in Training & Placement) 10 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC JDK Launch Paths and select the JDK option. And do the following to add the JDK. a. Click on add button. b. Click on Apply. 5. Select the “Launch” under JBOSS 4.x… Run mode and click Apply. 6. Click on OK of Preference window. a. By default Port no: 8080 because it take default of tomcat which is running on 8080. b. Change that Port no:- if get any error like JVM_8080 i.e. lifecycleException. -: Stating JBOSS :-  Change the Port number: 5555.  Start the JBOSS from myEclipse.  Open the browser and type http://localhost:5555/imx-console/  Enter username & password on popup window. -: Creating EJB Project in myEclipse :- 1. File new  “EJB Project” Project name: - E2Hello4JB and select J2EE1.4-EJB2.1 and finish. 2. You can see the following directory structure.
  • 11. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB. Java Training Center (No 1 in Training & Placement) 11 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC New otherXMLXML(Basic Tem)ejb-jar.xmlnextcreate xml file from DTD  select category. To deployselect the Project name and gotodeploy(8th ) Icon. Select Project E2Hello4JB add to your application server jBoss. -//sun microsystem, Inc.//DTD Enterprise JavaBeans 3.0 --: Create client Project for EJB :- 1. Create a “Java Project” E2client4JB.
  • 12. Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java Java Training Center (No 1 in Training & Placement) 12 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC Example:- File required:- 1. HelloRemote.java 2. HelloBean.java 3. HelloHome.java 4. Ejb-jar.xml 5. Jboss.xml 6. HelloClient.java
  • 13. Java Training Center (No 1 in Training & Placement) 13 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC 1. HelloHome.java package com.jtcindia.ejb2; importjava.rmi.*; importjavax.ejb.*; publicinterfaceHelloHomeextendsEJBHome{ publicHelloRemote create() throws createException, RemoteException; } 2. HelloRemote.java package com.jtcindia.ejb2; importjava.rmi.*; importjavax.ejb.EJBObject; publicinterfaceHelloRemoteextendsEJBObject{ public String getMessage(String name) throwsRemoteException; } 3. HelloBean.java package com.jtcindia.ejb2; importjavax.ejb.*; publicclassHelloBeanextendsSessionBean{ SessionContentsc=null; Public void setSessionContent(SessionContentsc){ System.out.println("setSesssionContent"); this.sc=sc;
  • 14. Java Training Center (No 1 in Training & Placement) 14 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC } Public void ejbActivate(){ System.out.println("ejbActivate"); } publicvoidejbPassivate(){ System.out.println("ejbPassivate()"); } publicvoidejbRemove(){ System.out.println("ejbReamove"); } publicvoidejbCreate(){ System.out.println("ejbCreate()"); } publicStringgetMessage(String name){ String msg="Hi"+name+"welcome to JTC EJB with JBOSS"; System.out.println(msg); returnmsg; } } 4. HelloClient.java package com.jtcindia.ejb2; importjava.util.*; importjavax.naming.*; public classHelloClient { publicstaticvoid main(String[] args) { try{ Properties p=newProperties();
  • 15. Java Training Center (No 1 in Training & Placement) 15 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC p.put("java.naming.factory.initial","org.jnp.interf aces.NamingContentFactory"); p.put("java.naming.provider.url","localhost:1099"); p.put("java.naming.factory.url.package","org.jboss. naming"); Contentctx=newInitialContext(p); Object o=ctx.lookup("JTCHelloHomeJNDI"); HelloHomehh=(HelloHome)o; HelloRemotehr=hh.create(); String msg=hr.getMessage("Som"); System.out.println(msg); msg=hr.getMessage("Som"); System.out.println(msg); }catch(Exception e){ e.printStackTrace(); } } } 5. ejb-jar.xml <?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEejb-jarPUBLIC"-//Sun MicroSystem,INC.//DTD Enterprise JavaBean 2.0//EN","http://Java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> <enterprise-beans> <session> <ejb-name>HelloEJB</ejb-name> <home>com.jtcindia.ejb2.HelloHome</home> <remote>com.jtcindia.ejb2.HelloRemote</remote>
  • 16. Java Training Center (No 1 in Training & Placement) 16 RMI Part 1 Author: SomPrakashRai www.jtcindia.org Copyright©JTC <ejb-class>com.jtcindia.ejb2.HelloBean</ejb-class> <session-type>Stateless</session-type> <trasaction-type>Container</trasaction-type> </session> </enterprise-beans> </ejb-jar> 6. jboss.xml <jboss> <enterprise-beans> <session> <ejb-name>HelloEJB</ejb-name> <jndi-name>JTCHelloHomeJNDI</jndi-name> </session> </enterprise-beans> </jboss>