aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Trouble running Advice EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Trouble running Advice EJB" Watch "Trouble running Advice EJB" New topic
Author

Trouble running Advice EJB

Dewang Lakhani
Greenhorn

Joined: Jul 05, 2006
Posts: 13
Please can anybody tell me what i need to have in my classpath.
I have deplyed it successfully. I have compiled it successfully. I am using an XP m/c. but when i do :-

java -cp C:\Dewang\j2EEStuff\projects\advice\AdviceAppClient.jar AdviceClient

I am getting "no classdef found error".

First i was also getting corba exceptions on java command, then i added rt.jar to my classpath. now i am geting the above error.


SCJP 1.4,SCBCD(IN PROGRESS)
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
try going \AdviceAdviceAppClient.jar;. this can make it work sometimes.
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Also try taking out rt.jar for the moment, the bad corba exception isnt because of not including rt.jar. It has to do with a naming problem.
Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
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...
Frederik Ericsson
Ranch Hand

Joined: Apr 27, 2005
Posts: 128
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...
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

if you say that we have give the JNDI name in weblogic, where do we ned to give

My Advisor works, and says : "You should use J2EE RI, as stated page 28"


[My Blog]
All roads lead to JavaRanch
Bharathi Kongara
Ranch Hand

Joined: Sep 15, 2005
Posts: 56
Dewang,

I used to have that problem. As Amitabha mentioned, try including ;. at the end of your classpath i.e. including the dir where .class file is.

Bharathi
Dewang Lakhani
Greenhorn

Joined: Jul 05, 2006
Posts: 13
Thanks a lot !!! It Worked Hurray!!!
I would like to repeat the formulae to run AdviceCient :-

IT IS TO INCLUDE ";." AFTER YOUR CLASSPATH i.e
TO Run use :-
"C:\Dewang\j2EEStuff\projects\advice>java -cp C:\j2sdkee1.3.1\lib\j2ee.jar;C:\Dewang\j2EEStuff\projects\advice\AdviceAppClient.jar;. AdviceClient"

To Compile use :-
"C:\Dewang\j2EEStuff\projects\advice>javac -classpath C:\j2sdkee1.3.1\lib\j2ee.jar;C:\Dewang\j2EEStuff\projects\advice\AdviceAppClient.jar;. AdviceClient.java"

I know it's not necessary to include j2ee.jar explicitly if you have it in your environment varibale. I have it set in my environment but then too i had to explicitly add it .
 
wood burning stoves
 
subject: Trouble running Advice EJB