• 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

Trouble running Advice EJB

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try going \AdviceAdviceAppClient.jar;. this can make it work sometimes.
 
Amit Batra
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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"
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
BWA HA HA HA HA HA HA! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic