• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chap 1 HF EJB

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I created the Session beans from the Cahpter 1 and the ear file sucessfully and while using the deploytool The Client jar was also created...

Now I have my Client java file which needs to use the Client jar file but its not compiling...

My project structure is as follows

projects\advice which has classes, src (used while creating the Session bean), ear file created, Client jar file and the Client java file I am trying to compile ...

The AppClient.jar file has the headfirst folder in it..

How do i compile the AdviceClient.java file ?

From the advice folder I tried to say javac -classpath entirepath\AdviceAppClient.jar AdviceClient.jar and it gives me errors like

AdviceClient.java:5: package javax.ejb does not exist
import javax.ejb.*;
^
AdviceClient.java:24: cannot access javax.ejb.EJBHome
file javax\ejb\EJBHome.class not found
Advice advisor = home.create();
^
AdviceClient.java:27: cannot access javax.ejb.EJBObject
file javax\ejb\EJBObject.class not found
System.out.println(advisor.getAdvice());

I have setup the J2EE_HOME and the JAVA_HOME and j2ee.jar is also in the classpath...

I am not sure what the {CLASSPATH}: means in the book
Can someone who ran this example before help me get some advice from the bean ?
 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to compile the client java file. But when I run it I get this error now.

com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)

Any idea what this is ?
 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at AdviceClient.go(AdviceClient.java:21)
at AdviceClient.main(AdviceClient.java:10)
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ClassCastException might mean that you are not narrowing the Object obtained from lookup() method properly. Did you check up with the JNDI name for your bean?

In any case, please post at least a part of your cilent code to help others help you out.

Regards,
Saket
 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The client code is pretty much the same as the chapter 1 code I think except that I changed the name of the method from getAdvice to getTheHint because the errata said it can cause problems.

import headfirst.Advice;
import headfirst.AdviceHome;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;


public class AdviceClient {

public static void main(String[] args) {
new AdviceClient().go();
}

public void go(){

try {
Context ct = new InitialContext();
Object o = ct.lookup("ejb/headfirst/Advice");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o,AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getTheHint());

} catch (ClassCastException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}

}
}
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic