This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB - Basic Question from

 
Frederik Ericsson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you can find a couple other topics about the same subject here.
 
Frederik Ericsson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic