my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes running EJB gives exception in 'main' of Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "running EJB gives exception in Watch "running EJB gives exception in New topic
Author

running EJB gives exception in 'main' of Client

Niran Javafan
Greenhorn

Joined: May 18, 2005
Posts: 1
Pls help resolving this.

My Codes are ....
1)Home interface
package headfirst;

import javax.ejb.*;
import java.rmi.RemoteException;

public interface Advice extends EJBObject{
public String getAdvice() throws RemoteException;
}

2)Component interface
package headfirst;

import javax.ejb.*;
import java.rmi.RemoteException;

public interface AdviceHome extends EJBHome{
public Advice create() throws CreateException, RemoteException;
}

3)Bean Class
package headfirst;
import javax.ejb.*;

public class AdviceBean implements SessionBean{

private String [] adviceStrings = {"One word:inappropriate.","You might want to rethink that haircut.","Your boss will respect yhou if you tell him waht you REALLY of him.","Visualize yourself with better clothes.","Of course you don't have to go to work today.","Do you really think you should be leaving the house like that?", "Read a book, once a year whether you need to or not."};

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");
}

public String getAdvice(){
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");
}
}


and the Client...

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;


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");

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

Advice advisor = home.create();
System.out.println(advisor.getAdvice());

} catch (Exception ex) {

ex.printStackTrace();
}
}
}


Thse codes could compile and make the .jar . The client also got compiled. But when running with the local srver following erro display.

first compilation.......
D:\J2eeProject\Advice>java -cp d:\j2eeproject\advice\AdviceAppClient.jar AdviceClient
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient


2nd compilation
D:\J2eeProject\Advice>java -cp d:\j2eeproject\advice\AdviceAppClient.jar;d:\j2sdkee1.3.1\lib\j2ee.jar Ad
viceClient
Exception in thread "main" java.lang.NoClassDefFoundError: AdviceClient


Let me know where the erro is..I used J2EE 1.3 RI .

Thanks in advance.
Niran
Shibu Raj
Greenhorn

Joined: Jan 24, 2005
Posts: 17
Hi Niran,
It seems like you have some class path issue. Look at the next post in the forum by Cliff DeRose. Will get some idea. Also make sure that you have the JDK run time in the path.( Hint from the post by Cliff DeRose).


Thanks
Shibu
 
GeeCON Prague 2014
 
subject: running EJB gives exception in 'main' of Client