How to set the java.rmi.server.codebase to classes generated with Maven?

I'm running the RMI example from here, and I'm trying to start the server:

package example.hello;

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server implements Hello {

    public Server() {}

    public String sayHello() {
        return "Hello, world!";

    public static void main(String args[]) {

        try {
            Server obj = new Server();
            Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

            // Bind the remote object's stub in the registry
            Registry registry = LocateRegistry.getRegistry();
            registry.bind("Hello", stub);

            System.err.println("Server ready");
        } catch (Exception e) {
            System.err.println("Server exception: " + e.toString());

When Maven build the project puts the generated classes (and also Hello.class interface file) in to target/classes and if I run rmiregistry from there everything is working fine.


  • Classes are there, and in facts if I run rmiregistry from target/classes it works
  • I tried basically all of the permutations of slashes, dots, double dots, etc.
  • I tried with System.setProperty("java.rmi.server.useCodebaseOnly", "false"); but nothing works.

What is the format of the java.rmi.server.codebase property if we want to use the classes generated by Maven?