Hello all,
am geting bit diff error..I read all the links.. which you gave ..but still am not geting it..cleared.
As I told you before am using weblogic8.1, first of all I would like to know do we need to give a name("Advisor") in JNDI in weblogic, as its mentioned in HFEJB page52 for RI Server. if you say that we have give the JNDI name in weblogic, where do we ned to give?
this is where I stand now...
AdviceBean.ejb
package headfirst;
import javax.ejb.*;
import weblogic.ejb.*;
import headfirst.*;
/**
* @ejbgen:session
* ejb-name = "Advice"
*
* @ejbgen:jndi-name
* remote = "ejb.AdviceRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name = "AdviceRemote" remote-home = "true" remote-home-name = "AdviceHome" local-class = "false" local-class-name = "AdviceLocal" local-home = "false" local-home-name = "AdviceLocalHome"
*/
public class AdviceBean implements SessionBean {
// OK, not very exciting advice!
You should come up with something better...
private
String[] adviceStrings = {"test", "test1", "test2", "test3"};
public void ejbActivate() {
System.out.println("ejb activate");
}
public void ejbPassivate() {
System.out.println("ejb passivate");
}
public void ejbRemove() {
System.out.println("ejb remove");
}
public void setSessionContext(SessionContext ctx) {
System.out.println("session context");
}
// this business method name is changed from the book, because
// there of a bug on some versions of the
J2EE RI
public String getMessage() {
System.out.println("in get advice");
int random = (int) (Math.random() * adviceStrings.length);
return adviceStrings[random];
}
public void ejbCreate() {
System.out.println("in ejb create");
}
}
AdviceClient.java
package headfirst;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;
// not all of these imports are used in this code...
// but in a *real* client you'd probably need at least
// java.rmi.RemoteException and javax.ejb.CreateException
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"); // replace with YOUR JNDI name for the bean
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getMessage());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I cant able to build with this file D:\Weblogic\user_projects\AdviceApp\AdviceApp\headfirst\AdviceClient.java
So I remove this client file for a while to build the .jar
after removing this client file, I can able to build. Done, now i got the AdviceApp.jar. again I brought back the client file to the same place..
I tried from cmd
D:\Weblogic\user_projects\AdviceApp\AdviceApp\headfirst>javac -classpath "C:\Program Files\j2sdkee1.3.1\lib\j2ee.jar";"D:\Weblogic\user_projects\AdviceApp\Advic
eApp\AdviceApp.jar" AdviceClient.java
AdviceClient.java:28: cannot resolve symbol
symbol : class Advice
location: class headfirst.AdviceClient
Advice advisor = home.create();
^
1 error
Please tel me how to get rid of this issue...