File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes HFEJB - Basic Question from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "HFEJB - Basic Question from " Watch "HFEJB - Basic Question from " New topic
Author

HFEJB - Basic Question from

Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
Hello Guys,

am using HFEJB, using Weblogic8.1..

First example in HFEJB.
Advice Application

I can able to build & deploy the Advice appln, while am trying to compile and run the client code...am geting error. Here is the client code

public class AdviceClient {

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

public void go() {
try {
Context ic = new InitialContext();


Object o = ic.lookup("Test1"); // replace with YOUR JNDI name for the bean

AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o, AdviceHome.class);

Advice advisor = home.create(); //GETING ERROR HERE(NO TYPE WITH THIS NAME COULD NOT BE FOUND)

System.out.println(advisor.getMessage());

} catch (Exception ex) {
ex.printStackTrace();
}
}
}

am geting error in this line

Advice advisor = home.create(); //GETING ERROR HERE(NO TYPE WITH THIS NAME COULD NOT BE FOUND)

could you please fix it.

Cheers
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Hi,

you can find a couple other topics about the same subject here.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
Hello Valetin & 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

1 error

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...
[ October 02, 2006: Message edited by: Frederik Ericsson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFEJB - Basic Question from
 
Similar Threads
HFEJB.. help needed in calling from client
how to run the AdviceClient
Trouble running Advice EJB
Weblogic with Ejb, HFEJB
JNDI