f



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

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?


0
phenry_w (70)
2/9/2004 7:01:59 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
814 Views

Similar Articles

[PageSpeed] 47

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

David


"Flip" <!no_spam!phenry_w@hotmail.com> wrote in message
news:HOQVb.20713$R6H.16813@twister01.bloor.is.net.cable.rogers.com...
> 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" );
>   file://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?
>
>


0
darmour (4)
2/9/2004 7:41:02 PM
Flip wrote:
> 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.

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology


0
SeeMySites (5478)
2/9/2004 9:14:44 PM
"Flip" <!no_spam!phenry_w@hotmail.com> wrote in message
news:HOQVb.20713$R6H.16813@twister01.bloor.is.net.cable.rogers.com...
> 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)


0
dibblego (448)
2/9/2004 10:13:12 PM
Reply: