Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running EJB gives exception in 'main' of Client

 
Niran Javafan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic