Hi,
I ran a rmi program downloaded from a site. It executed yesterday but today I am trying to run the same program from a different folder but I am getting error in the server:
java -Djava.security.poicy=policy HelloServer &
Hello Server failed: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
My interface code is:
HelloInterface.java
import java.rmi.*;
public interface HelloInterface extends Remote {
public String say(String m) throws RemoteException;
}
Hello.java
import java.rmi.*;
import java.rmi.server.*;
public class Hello extends UnicastRemoteObject implements HelloInterface {
private String message; // Strings are serializable
public Hello (String msg) throws RemoteException {
message = msg;
}
public String say(String m) throws RemoteException {
return new StringBuffer(m).reverse().toString()+ "\n" + message; }}
Compile:
D:\java prog\2017Self\rmi>javac Hello.java
HelloClient.java
import java.rmi.*;
class HelloClient {
public static void main (String[] args) {
try {
if(args.length <0){
System.err.println("Usage: java HelloClient string - \n");
System.exit(1);
}
HelloInterface hello = (HelloInterface)Naming.lookup("//localhost/Hello");
System.out.println(hello.say(args[1])); }
catch (Exception e) {
System.out.println("HelloClient exception: " + e);
}
}}
Compile:
D:\java prog\2017Self\rmi>javac HelloClient.java
HelloServer.java
import java.rmi.*;
class HelloServer {
public static void main (String[] argv) {
if(System.getSecurityManager() == null)
System.setSecurityManager(new SecurityManager());
try {
Naming.rebind("Hello",new Hello("Hello, world!"));
System.out.println("Hello Server is ready."); }
catch (Exception e) {
System.out.println("Hello Server failed: " + e); } }}
Compile:
D:\java prog\2017Self\rmi>javac HelloServer.java
Policy file
Note the name of this file is policy without any extension. Write the following code on notepad editor and then save as “policy”
grant{
permission java.security.AllPermission;
};
I have also started the rmiregistry but its running from different window despite I wrote “&” after the command:
rmiregistry &
I don’t know why its occupying the command window even when I am using “&” sign.
Is it required to run the rmiregistry and rmi server from the same command window?
Some body please guide me why I am getting security error?
Zulfi.