Hi, This problem occured to me while running the client code (HeadFirst EJB page 57) after successful deployment of Advice EJB.
C:\EJB\projects\advice>java -cp .;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee 1.3.1\lib\j2ee.jar;C:\EJB\projects\advice\classes AdviceClient java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta bleRemoteObject.java:293) at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134) at AdviceClient.go(AdviceClient.java:15) at AdviceClient.main(AdviceClient.java:9)
I used following code for client (given on HFE page 57) :
Rajesh, for window, use the following commands to compile and run:
To compile: c:\HF>javac -classpath %CLASSPATH%;AdviceAppClient.jar AdviceClient.java
To run: c:\HF>java -cp %CLASSPATH%;AdviceAppClient.jar AdviceClient
You don't to have the substitute CLASSPATH with ".;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee 1.3.1\lib\j2ee.jar;".
For window, the command is slightly different from UNIX. It uses %.
HTH, Joyce [ May 16, 2004: Message edited by: Joyce Lee ]
Surendra Poranki
Greenhorn
Joined: May 16, 2004
Posts: 5
posted
0
Try These
To Compile C:\projects\advice>javac -classpath "%CLASSPATH%;AdviceAppClient.jar" AdviceClient.java
To Run C:\projects\advice>java -cp "%CLASSPATH%;AdviceAppClient.jar" AdviceClient
When u run if u get the Corba.Error try to change the name of the getAdvice() method to something else and redeploy it .
Originally posted by Rajesh Srivastava: Hi, This problem occured to me while running the client code (HeadFirst EJB page 57) after successful deployment of Advice EJB.
C:\EJB\projects\advice>java -cp .;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee 1.3.1\lib\j2ee.jar;C:\EJB\projects\advice\classes AdviceClient java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta bleRemoteObject.java:293) at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134) at AdviceClient.go(AdviceClient.java:15) at AdviceClient.main(AdviceClient.java:9)
I used following code for client (given on HFE page 57) :
public class AdviceClient { public static void main(String [] args) { new AdviceClient().go(); } public void go() { try { Context ic = new InitialContext(); Object o = ic.lookup("Advisor"); AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class); Advice advisor = home.create(); System.out.println(advisor.getAdvice()); } catch(Exception ex) { ex.printStackTrace(); } } }
I am using following versions of JSDK and J2SDKEE: j2sdk1.4.0 and j2sdkee1.3.1
Looking forward to help, rajesh - SCJP (1.4)
Rajesh Srivastava
Greenhorn
Joined: May 14, 2004
Posts: 25
posted
0
Thanx, It worked after using classpath as shown. A corba error was displayed but it was removed on changing the name of function getAdvice() to getAdv(). But I could not get why name change removes the corba error ?