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

Discussion in 'Java' started by Flip, Feb 9, 2004.

  1. Flip

    Flip Guest

    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?
    Flip, Feb 9, 2004
    #1
    1. Advertising

  2. Flip

    David Armour Guest

    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!> wrote in message
    news:HOQVb.20713$...
    > 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?
    >
    >
    David Armour, Feb 9, 2004
    #2
    1. Advertising

  3. 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
    Andrew Thompson, Feb 9, 2004
    #3
  4. Flip

    Tony Morris Guest

    "Flip" <!no_spam!> wrote in message
    news:HOQVb.20713$...
    > 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)
    Tony Morris, Feb 9, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Miguel Dias Moura
    Replies:
    2
    Views:
    323
    Martin
    Jun 22, 2004
  2. Replies:
    1
    Views:
    2,112
    Irmen de Jong
    Jun 22, 2004
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    838
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,667
    Smokey Grindel
    Dec 2, 2006
  5. lorlarz
    Replies:
    82
    Views:
    617
    todd.levinson
    Sep 12, 2008
Loading...

Share This Page