C:\LearnJava\TIJ\Chapter8\Ex2\Package1\Ex2Interface.java the contents of
which follows
package Ex2.Package1;
public interface Ex2Interface
{
public void Method1( );
public void Method2( );
public void Method3( );
}
and C:\LearnJava\TIJ\Chapter8\Ex2\Package2\Ex2Imp.java the contents of
which follows
package Ex2.Package2;
import Ex2.Package1.*;
public class Ex2Imp implements Ex2Interface
{
public void Method1( ) { System.out.println("Method1
Implementation"); }
public void Method2( ) { System.out.println("Method2
Implementation"); }
public void Method3( ) { System.out.println("Method3
Implementation"); }
public static void main(String[] args)
{
Ex2Imp E = new Ex2Imp( );
E.Method1( );
E.Method2( );
E.Method3( );
}
}
I compile the interface successfully by cd'ing to the Package1 directory
and issueing: javac Ex2Interface.java
I then compile the implementation successfully by cd'ing to the Package2
directory and issueing: javac -classpath C:\LearnJava\TIJ\Chapter8
Ex2Imp.java
The problem arises when I try to run Ex2Imp.java by issueing: java
-classpath C:\LearnJava\TIJ\Chapter8 Ex2Imp
I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: Ex2Imp
If I issue the java command withouth the classpath option I get
something a little different:
Exception in thread "main" java.lang.NoClassDefFoundError: Ex2Imp (wrong
nam
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)
I apologize for being so long winded here, but I wanted to be sure to
include all of the details. I'm really pulling my hair out over what I
am sure is a small mistake. Thanks in advance for any help anyone can
offer.
-Jason
Jason <jas...@optonline.net> wrote in message
news:3A5A2D4B...@optonline.net...
-Jason
Because the class you're trying to run *isn't* called Ex2Imp. It's
called Ex2.Package2.Ex2Imp.
Rather than compiling things from the directory they're in, do
*everything* from a "base" directory:
C:\LearnJava\TIJ\Chapter8> javac Ex2\Package2\*.java
C:\LearnJava\TIJ\Chapter8> java Ex2.Package2.Ex2Imp
--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet
On Tue, 9 Jan 2001, Jason wrote: