Results 1 to 2 of 2
  1. #1
    Norberhuis is offline Member
    Join Date
    Jan 2009
    Location
    Delft
    Posts
    13
    Rep Power
    0

    Default Codebase property for RMI

    I am setting up a RMI server, but I am running into a error I am not able to solve. I use Ubuntu with Eclipse and a Maven project.
    I get the following error:
    Error: Could not find or load main class dsb.bar.flowmeter.flowserver.FlowServer

    To get RMI working properly you need to setup the codebase and a policy. You do that with adding the following vm commands to the run configuration in Eclipse:
    -Djava.security.policy=server.policy dsb.bar.flowmeter.flowserver.FlowServer
    -Djava.rmi.server.codebase=file://$(workspace_loc:flowserver)/target/classes/

    The policy file contains:
    Java Code:
    grant codeBase "file:///home/norberhuis/workspace/DSB/flowmeter/flowserver/target/classes/" {
        permission java.security.AllPermission;
    };
    The class I am running is:
    Java Code:
    package dsb.bar.flowmeter.flowserver;
    
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.ArrayList;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import dsb.bar.flowmeter.flowclient.IDisplayClient;
    
    /**
     * Server that FlowClients can observe using RMI.
     * 
     * @author norberhuis
     * 
     */
    public class FlowServer implements IDisplayServer {
    
    	private ArrayList<IDisplayClient> observers;
    
    	static final Logger LOG = LoggerFactory.getLogger(FlowServer.class);
    
    	/**
    	 * Instantiate the server.
    	 */
    	public FlowServer() {
    		LOG.info("Starting FlowServer");
    		observers = new ArrayList<IDisplayClient>();
    
    	}
    
    	public void registerObserver(IDisplayClient observer) throws RemoteException {
    		LOG.info("Observer added");
    		observers.add(observer);
    	}
    
    	public static void main(String[] args) {
    		// A security manager is needed for RMI.
    		if (System.getSecurityManager() == null) {
    			System.setSecurityManager(new SecurityManager());
    		}
    
    		FlowServer server = new FlowServer();
    		try {
    			IDisplayServer remote = (IDisplayServer) UnicastRemoteObject.exportObject(server, 0);
    			String name = "DisplayServer";
    
    			Registry registry = LocateRegistry.getRegistry();
    			registry.rebind(name, remote);
    
    		} catch (RemoteException e) {
    			e.printStackTrace();
    		}
    
    	}
    }
    Anybody got an idea what I am doing wrong? Thanks in advance.

  2. #2
    Norberhuis is offline Member
    Join Date
    Jan 2009
    Location
    Delft
    Posts
    13
    Rep Power
    0

    Default Re: Codebase property for RMI

    The problem was that I was actually running an integrationtest that do not get compiled. The main was exactly the same in the integrationtest as in this class. If I run the flowserver class itself does work.

Similar Threads

  1. Codebase property for RMI
    By Norberhuis in forum New To Java
    Replies: 0
    Last Post: 06-23-2013, 10:38 PM
  2. codebase problem
    By newbie123 in forum Java Applets
    Replies: 1
    Last Post: 04-16-2010, 04:04 AM
  3. XML property
    By Abder-Rahman in forum XML
    Replies: 1
    Last Post: 09-27-2009, 08:10 PM
  4. Replies: 0
    Last Post: 06-25-2009, 06:28 AM
  5. File Property
    By Juggler in forum New To Java
    Replies: 0
    Last Post: 08-10-2008, 08:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •