Reputation: 2115
I am writing some Java classes to implement RMI. I wrote all the classes and the program worked fine. But from the very next day I am getting a compiler error indicating that the absence of files:
Filename: ServerInterface.java
import java.rmi.*;
public interface ServerInterface extends Remote
{
public double sum(double[] temp) throws RemoteException;
};
Filename: ServerImplement.java
import java.rmi.*;
import java.rmi.server.*;
public class ServerImplement extends UnicastRemoteObject implements ServerInterface
{
public ServerImplement() throws RemoteException
{
}
public double sum(double[] temp) throws RemoteException
{
double sum=0;
int len=temp.length;
for(int i=0;i<len;i++)
sum+=temp[i];
return sum;
}
};
Even to prove that its not any filename errors:
F:\E\java\rmi final>dir
Volume in drive F is My Volume
Volume Serial Number is E0F9-4F89
Directory of F:\E\java\rmi final
22-01-2011 23:23 <DIR> .
22-01-2011 23:23 <DIR> ..
22-12-2009 13:09 1,849 additionImplementer_Stub.class
21-01-2011 21:52 1,076 Client.class
18-01-2011 02:54 649 Client.java
21-01-2011 21:52 1,847 ClientTry.class
18-01-2011 02:54 1,268 ClientTry.java
21-01-2011 21:52 444 ServerImplement.class
18-01-2011 02:30 386 ServerImplement.java
18-01-2011 02:54 1,783 ServerImplement_Stub.class
21-01-2011 21:54 209 ServerInterface.class
22-12-2009 12:07 132 ServerInterface.java
21-01-2011 21:52 919 ServerMain.class
18-01-2011 02:36 409 ServerMain.java
12 File(s) 10,971 bytes
If I try: javac *.java
, it works fine (but trying java on any of the .class files leads to error : Exception in thread "main" java.lang.NoClassDefFoundError: ServerMain
If I try javac ServerImplement.java
I get an error (in fact none of my java programs are able to link):
(I am in the same directory)
E:\java\rmi final>javac ServerMain.java
ServerImplement.java:4: cannot find symbol
symbol: class ServerInterface
public class ServerImplement extends UnicastRemoteObject implements ServerInterface
^
1 error
The program is even working fine at my college lab. Should I reinstall JDK? Or is there any way to provide linking explicitly?
Upvotes: 1
Views: 6229
Reputation: 4122
There is no linking when compiling java code. The compiler still needs to find all classes that are referenced by the code being compiled. If you don't use packages, make sure you run javac in the same directory your .java is in. A javac *.java should be able to resolve your problems.
Upvotes: 0
Reputation: 1503469
Sounds like you don't have "." on the classpath. Try to run it like this:
java -classpath . ServerMain
Have a look at your CLASSPATH environment variable to see if that's getting in the way - these days I typically find it's easiest not to have one, to be honest.
Upvotes: 4