classpath idiot

Discussion in 'Java' started by justdoit693, Jul 22, 2003.

  1. justdoit693

    justdoit693 Guest

    I've been programming java for a while now so i'm not a novice (although
    this problem is making me feel like one)...heres the scenario. In fact,
    i've done all this before so i'm not sure what i'm missing here.

    I've got a JAR file that acts as a library that contains an interface called
    com.app.CallbackInterface

    I have another class that takes an implementation of a CallbackInterface in
    the same JAR file and the same path.

    Now i've created a test application with this basic code.

    import com.app.* ;

    public class MyTestApp implements CallbackInterface {
    public static void main(String args[]) {
    AppMonitor app = new AppMonitor(new MyTestApp()) ;

    }

    // callback interface methods go here...

    }

    The code compiles just fine but I get a NoClassDefFoundError when I try to
    run the app.

    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/app/CallbackInterface
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    Of course, i've got my class path pointing to the JAR file mentioned above
    (the code wouldn't compile if I didn't). FYI, i'm using ANT with a single
    classpath configured and my <javac> task refers to the path by reference.
    Also, just for convenience I have a run target that uses the same
    classpathref for the <java> task as the <javac> task so I know they are both
    using the correct classpath. I've also setup a batch file that creates the
    correct classpath in case i'm messing up with ANT somehow...

    I'm completely stumped at this point. What am I missing?

    thanks in advance for any help.
    justdoit693, Jul 22, 2003
    #1
    1. Advertising

  2. justdoit693

    Roedy Green Guest

    Roedy Green, Jul 22, 2003
    #2
    1. Advertising

  3. justdoit693

    justdoit693 Guest

    justdoit693, Jul 22, 2003
    #3
  4. justdoit693

    Roedy Green Guest

    On Mon, 21 Jul 2003 19:16:02 -0700, "justdoit693"
    <> wrote or quoted :

    >You read the part where I said it compiled...yes?


    Yes. Exceptions can't very well happen unless you had a successful
    compile.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 22, 2003
    #4
  5. justdoit693

    Moshe Sayag Guest

    You have to add the newly generated classes to the classpath of the
    <java> target?

    for example:
    javac -classpath mylib.jar -d out CallbackInterface
    java -classpath mylib.jar;out CallbackInterface

    Notice the the different classpath arg.

    Moshe

    justdoit693 wrote:

    > I've been programming java for a while now so i'm not a novice (although
    > this problem is making me feel like one)...heres the scenario. In fact,
    > i've done all this before so i'm not sure what i'm missing here.
    >
    > I've got a JAR file that acts as a library that contains an interface called
    > com.app.CallbackInterface
    >
    > I have another class that takes an implementation of a CallbackInterface in
    > the same JAR file and the same path.
    >
    > Now i've created a test application with this basic code.
    >
    > import com.app.* ;
    >
    > public class MyTestApp implements CallbackInterface {
    > public static void main(String args[]) {
    > AppMonitor app = new AppMonitor(new MyTestApp()) ;
    >
    > }
    >
    > // callback interface methods go here...
    >
    > }
    >
    > The code compiles just fine but I get a NoClassDefFoundError when I try to
    > run the app.
    >
    > Exception in thread "main" java.lang.NoClassDefFoundError:
    > com/app/CallbackInterface
    > at java.lang.ClassLoader.defineClass0(Native Method)
    > at java.lang.ClassLoader.defineClass(Unknown Source)
    > at java.security.SecureClassLoader.defineClass(Unknown Source)
    > at java.net.URLClassLoader.defineClass(Unknown Source)
    > at java.net.URLClassLoader.access$100(Unknown Source)
    > at java.net.URLClassLoader$1.run(Unknown Source)
    > at java.security.AccessController.doPrivileged(Native Method)
    > at java.net.URLClassLoader.findClass(Unknown Source)
    > at java.lang.ClassLoader.loadClass(Unknown Source)
    > at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    > at java.lang.ClassLoader.loadClass(Unknown Source)
    > at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    >
    > Of course, i've got my class path pointing to the JAR file mentioned above
    > (the code wouldn't compile if I didn't). FYI, i'm using ANT with a single
    > classpath configured and my <javac> task refers to the path by reference.
    > Also, just for convenience I have a run target that uses the same
    > classpathref for the <java> task as the <javac> task so I know they are both
    > using the correct classpath. I've also setup a batch file that creates the
    > correct classpath in case i'm messing up with ANT somehow...
    >
    > I'm completely stumped at this point. What am I missing?
    >
    > thanks in advance for any help.
    >
    >
    >
    >
    Moshe Sayag, Jul 22, 2003
    #5
  6. On Mon, 21 Jul 2003 17:30:35 -0700, "justdoit693" <> wrote:

    > Of course, i've got my class path pointing to the JAR file mentioned above
    > (the code wouldn't compile if I didn't). FYI, i'm using ANT with a single
    > classpath configured and my <javac> task refers to the path by reference.
    > Also, just for convenience I have a run target that uses the same
    > classpathref for the <java> task as the <javac> task so I know they are both
    > using the correct classpath.


    java and javac can use CLASSPATH and its variants in slightly
    different ways. And ant may well have some setting you don't
    expect, either on the configured command line or in the
    environment.

    > I've also setup a batch file that creates the
    > correct classpath in case i'm messing up with ANT somehow...


    That's good, eliminate ANT so you can precisely set and see what
    the CLASSPATH is set to. I would use a bare command line with
    -cp to run your app and see if it succeeds. Here are the steps
    I would take:

    1. Go to a command line.
    2. Unset CLASSPATH environment variable (so as not to find
    anything unexpected).
    3. Locate all the pieces that the app will need in order to run.
    3. Run your app using "java -cp myjar.jar;<other stuff> MyTestApp".
    Replace "<other stuff>" with whatever else your app needs in
    order to run. Does it run? If not, what is it missing?
    4. Then start adding CLASSPATH items back in until it starts
    working.
    5. Figure out exactly why a particular item causes things to work
    or not work.

    I suspect that you will find one of two things.

    a) You have a bad copy of CallbackInterface lying around some-
    where that is either not in a package, or in a different
    package,

    or

    b) Your CLASSPATH setting in ANT is not what you think it is.

    > I'm completely stumped at this point. What am I missing?


    You don't provide any concrete details on what your classpath
    settings are for us to be specific, so you will have to trace
    it down, or give us more info, like exactly what the commands
    are, and what the env settings are.

    --Joe
    Joseph Millar, Jul 22, 2003
    #6
    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.

Share This Page