|
Actual Client Code => C:\myejb\myClient.java
|
Color Coding :
Gray : Comments
Maroon : Skeleton Framework for Client Code
Blue : Code Related to Get the Bean Info
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
// import Home and Remote Interfaces
import myRemote;
import myHome;
public class myClient
{
public static void main(String[] args)
{
try
{
//Locate the Home Interface
Context initial = new InitialContext();
//Retrieve the object bound to the name myJNDI
Object objref = initial.lookup("myJNDI");
//Narrow the reference to a myHome object
myHome home = (myHome)PortableRemoteObject.narrow(objref, myHome.class);
//Invoke create method of myHome Object
myRemote myRemote_object = home.create();
//Calling a business method "find_income"
double income = myRemote_object.find_income(3500,1200,800);
//Calling a business method "find_savings"
int expense=2000;
double savings = myRemote_object.find_savings(income,expense);
//Display final output at command prompt
System.out.println("My income is " +String.valueOf(income));
System.out.println("My Savings is" +String.valueOf(savings));
//Remove the Object Created
myRemote_object.remove();
}
catch (Exception ex)
{
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
|
|
Compiling the Client's Code : Create C:/myejb/compileClient.bat
|
set J2EE_HOME=C:\j2sdkee1.3.1
set CPATH=C:\j2sdkee1.3.1\lib\j2ee.jar;C:\myejb
javac -classpath %CPATH% myClient.java
|
|
C:\myejb\>compileClient
|
|
Running the Client : Create C:/myejb/testClient.bat
|
set J2EE_HOME=C:\j2sdkee1.3.1
set CPATH=C:\j2sdkee1.3.1\lib\j2ee.jar;C:\myejb;myAppClient.jar
java -classpath "%CPATH%" myClient
|
C:\myejb\>testClient
Caught an unexpected Exception!
javax.naming.CommunicationException: Can't find SerialContextProvided
........
..................
OOPS! oh my god what to do now ? what went wrong ? :-(
Start the Server :-)
C:\myejb\>deploytool
........
..................
J2EE Server startup complete.
C:\myejb\>testClient
My income is 5500.0
My Savings is 3500.0
|
NEXT >> Working with Session Beans
|
|
My Dream to be your Friend and Create a Group of Intelligent and Understanding Programmers
|
If you like this article and/or code mailme or Join our small Java User Group which is by the Programmers for the Programmers ,
Till we meet next time BYE Kind Regards - James Smith
|
|
Java, J2EE, J2SE and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc.
in the United States and other countries.
|