This discussion is archived
1 Reply Latest reply: May 19, 2008 11:26 AM by 807581 RSS

setup rmi, policy file, server code base on netbeans 6.0

807581 Newbie
Currently Being Moderated
can some one please please please tell me how to setup the policy file, codebase that in netbeans project directory, so that i can run rmi program. where should i put the policy file?

100 thanks
  • 1. Re: setup rmi, policy file, server code base on netbeans 6.0
    807581 Newbie
    Currently Being Moderated
    after i put the policy file in project directory i add " �Djava.security.policy=policy" to vm options and i got error says "java.lang.NoClassDefFoundError: �Djava/security/policy=policy
    Exception in thread "main"
    Java Result: 1
    "

    the full code is

    package rmitestclient;

    import java.rmi.*;
    public interface Adder extends java.rmi.Remote
    {
    int add(int x, int y) throws RemoteException;
    }

    package rmitestclient;
    import java.io.*;
    import java.util.*;
    import java.rmi.*;
    import java.rmi.registry.*;
    import java.net.MalformedURLException;
    // creates two random numbers & adds them using the server method add()
    public class AdderClient
    {
    public static void main(String args[])
    {
    /*int x = (int) (Math.random() * 100);
    int y= (int) (Math.random() * 100);
    try {
    Adder a = (Adder)
    Naming.lookup("rmi://localhost:1099/AdderImpl");
    System.out.println("sum of "+ x +
    " and " + y + " = " + a.add(x,y));
    }
    catch (Exception re)
    {  System.out.println(re);
    }*/
    try
    {
    BufferedReader br = new BufferedReader(new FileReader("policy"));
    System.out.println(br.readLine());

    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }

    grant {
    permission java.security.AllPermission;
    };

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package rmitest;

    import java.rmi.*;
    import java.rmi.server.*;
    import java.net.MalformedURLException;

    public class AdderImpl extends UnicastRemoteObject
    implements Adder
    {
    public AdderImpl() throws RemoteException {     }
    public int add(int x, int y)
    throws RemoteException { return x + y;    }
    public static void main(String args[])
    {  System.setSecurityManager(new RMISecurityManager());
    try {
    AdderImpl server = new AdderImpl();
    Naming.rebind("rmi://localhost:13759/AdderImpl",server);//13759
    System.out.println("Created and registered AdderImpl object");
    }
    /*catch (RemoteException re)
    {  re.printStackTrace();        }
    catch (MalformedURLException me)
    {   me.printStackTrace(); }
    */catch(Exception e)
    {
    e.printStackTrace();
    }
    }
    }

    please help