*
The moose likes Beginning Java and the fly likes Java classpath,class not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java classpath,class not found error" Watch "Java classpath,class not found error" New topic
Author

Java classpath,class not found error

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
I have directory c:\RMI\src\java\rmiExample

Under this directory there are two classes which belong to same package rmiExample.

There is a Hello.java class and HelloInterface.java class

Hello.java implements the HelloInterface.java interface.

But when I compile the Hello.java from command prompt from c:\RMI\src\java\rmiExample directory I get error that can not find symbol HelloInterface

Not sure why java is unable to locat ehte interface if both the class and the interface are in the same package and directory.


Any pointers?

Thanks

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
What is your classpath?
Do any of those classes have package declarations?
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Here is the java code

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Campbell Ritchie wrote:What is your classpath?
Do any of those classes have package declarations?


My CLasspath is: C:\RMI\src\java\rmiExample
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2835
    
  11

Classpaths can be tricky, especially once you start using packages ... which you should always do of course. Here, if you compile both classes at once it should work:

* rmiExample > javac *.java

But if you want to compile the interface first, then you'll have to give a classpath when compiling Hello.java, and the classpath entry in this case is the the directory above rmiExample:

* rmiExample > javac -cp .. Hello.java

When the compiler sees a reference to rmiExample.HelloInterface, it looks for the class file in an rmiExample directory relative to each entry in the classpath.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java classpath,class not found error
 
Similar Threads
Compilation using classpath
EJB Compilation problem
RMI: ClassNotFoundException: Impl_Stub
package trouble
registry binding problem in RMI