Hello All
after i got:
C:\csc193\examples\network>
java -Djava..rmi.server.codebase=file:/..\..\ -D
java.security.policy=RMISecurity.policy examples.network.StudentEnrollment
student objects bound .
what does that(the exception) mean?how can i fix that?
do i need to set up anything?
thanks for your time.
here is the full exception:
===========================
C:\csc193\examples\network>java -Djava.security.policy=RMISecurity.policy e
xamples.network.StudentClient
java.rmi.NotBoundException: Student1001
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(U
nknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at examples.network.StudentClient.main(StudentClient.java:17)
===========================
here are my app's files:
=============================
grant
{
permission java.net.SocketPermission "*:1024-65535",
"connect,accept";
};
============================
package examples.network;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Student extends Remote
{
public int getID() throws RemoteException;
public void setName(
String name) throws RemoteException;
public String getName() throws RemoteException;
public int getCredits() throws RemoteException;
public int addCredits(int credits) throws RemoteException;
}
=======================================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentClient
{
private static final String HOST_NAME="localhost";
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
Student s1001=(Student) Naming.lookup("//"+HOST_NAME+"/Student1001");
Student s1005=(Student) Naming.lookup("//"+HOST_NAME+"/Student1005");
System.out.println(s1001.getName());
System.out.println(s1005.getName());
System.out.println(s1001.getCredits());
s1001.addCredits(3);
s1001.setName("Elaine Goldman");
System.out.println(s1001.getName());
System.out.println(s1001.getCredits());
}
catch(Exception x)
{
x.printStackTrace();
}
}
}
===============================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentEnrollment
{
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}
try
{
StudentImpl[] students=
{
new StudentImpl( 1001,"Matt1 "),
new StudentImpl( 1002,"Matt2 "),
new StudentImpl( 1003,"Matt3 "),
new StudentImpl( 1004,"Matt4 "),
new StudentImpl( 1005,"Matt5 ")
};
for(int i=0;i<students.length;i++)
{
int id =students[i].getID();
Naming.rebind("student"+id,students[i]);
}
System.out.println("student objects bound .");
}
catch(Exception x)
{
x.printStackTrace();
}
}
}
==================================
package examples.network;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class StudentImpl extends UnicastRemoteObject
implements Student
{
private int ID;
private String name;
private int credits=0;
public StudentImpl(int ID,String name)throws RemoteException
{
this.ID=ID;
this.name=name;
}
public int getID() throws RemoteException
{
return ID;
}
public void setName(String name) throws RemoteException
{
this.name=name;
}
public String getName() throws RemoteException
{
return name;
}
public int getCredits() throws RemoteException
{
return credits;
}
public int addCredits(int credits) throws RemoteException
{
return (this.credits +=credits);
}
}
============================================