Can you see why I'm getting a NoClassDefFoundError here? I can't see it :<

F

Flip

I'm going through the HeadFirt EJB book, and I stuck on one example. :< The
code is here (simple example used to illustrate simple ejb creation/usage,
but my example has that commented out).
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient{

public static void main( String[] args ){
System.err.println( "BEG" );
//new AdviceClient().go();
System.err.println( "END" );
}

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.err.println( advisor.getAdvice() );
} catch( Exception ex ){
ex.printStackTrace();
}
}
}


I can compile it with the right -classpath and all is good. But when I goto
run it, I get the error message java.lang.NoClassDefFoundError:
AdviceClient. Why?

As far as I can see the classname matches the public classname, there is a
public static void main( String[] ) method, and it compiles, but it can't
seem to find the main, why? I can create another simple test.java code with
just the mainline and all runs correctly. Is there something with classpath
setup that screwing things up?
 
D

David Armour

Likely a class referenced inside of AdviceClient has been superceded and a
method signature of that class is improper or missing.

David
 
A

Andrew Thompson

Flip said:
I'm going through the HeadFirt EJB book, and I stuck on one example.
:< The code is here (simple example used to illustrate simple ejb
creation/usage, but my example has that commented out). ....
I can compile it with the right -classpath and all is good. But when
I goto run it, I get the error message java.lang.NoClassDefFoundError:
AdviceClient. Why?

Are you specifying the -classpath when you run it?

java -classpath . AdviceClient

should work.
 
T

Tony Morris

Flip said:
I'm going through the HeadFirt EJB book, and I stuck on one example. :< The
code is here (simple example used to illustrate simple ejb creation/usage,
but my example has that commented out).
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient{

public static void main( String[] args ){
System.err.println( "BEG" );
//new AdviceClient().go();
System.err.println( "END" );
}

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.err.println( advisor.getAdvice() );
} catch( Exception ex ){
ex.printStackTrace();
}
}
}


I can compile it with the right -classpath and all is good. But when I goto
run it, I get the error message java.lang.NoClassDefFoundError:
AdviceClient. Why?

As far as I can see the classname matches the public classname, there is a
public static void main( String[] ) method, and it compiles, but it can't
seem to find the main, why? I can create another simple test.java code with
just the mainline and all runs correctly. Is there something with classpath
setup that screwing things up?

This means that the Java Runtime cannot find the class AdviceClient.
Make sure the class (AdviceClient.class) is in the current directory and
that you have set your CLASSPATH appropriately (probably shouldn't have a
CLASSPATH set at all).
http://www.xdweb.net/~dibblego/javafaq/javafaq.html#q5

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,795
Messages
2,569,644
Members
45,358
Latest member
TreyTritt8

Latest Threads

Top