Ah, legend! Thanks Roel. I guess it required a bit more playing around on my behalf.
The problem seems to be as you reported - you need to start the webserver in the root directory of Java package containing the classes to be served, otherwise the webserver cannot find them when requested for them.
In more concrete terms:
- I was starting my webserver in the directory
E:\RMI-Example-2
- The path to the class being requested was
E:\RMI-Example-2\classes\core\java\book\chpt10\example\Warehouse.class
- The webserver got a request for
'/core/java/book/chpt10/example/Warehouse.class'
- The webserver was looking at the following location
'E:/RMI-Example-2/core/java/book/chpt10/example/Warehouse.class' as the webserver is set up to start looking from the root of the directory from it was launched from i.e.
E:\RMI-Example-2
- Now, start the webserver in the directory
E:\RMI-Example-2\classes
- The webserver once again gets a request for
'/core/java/book/chpt10/example/Warehouse.class'
- But this time it is looking at the following location
'E:/RMI-Example-2/classes/core/java/book/chpt10/example/Warehouse.class' , and it successfully finds the file
Just for my own curiosity, I actually ran the WarehouseServer from the directory E:\RMI-Example-2 to rule out the problem being a classpath issue with the WarehouseServer class, and to see if it was just a problem with the webserver.
I ran the following and all commands ran successfully without any exception being thrown:
* C:\>rmiregistry
* E:\RMI-Example-2\classes>java -cp . core.java.book.chpt10.example.NanoHTTPD 8080
* E:\RMI-Example-2>java -cp classes -Djava.rmi.server.codebase=http://localhost:8080/ core.java.book.chpt10.example.WarehouseServer
* E:\RMI-Example-2>java -cp classes core.java.book.chpt10.example.WarehouseClient
So, I conclude the problem is just with the webserver - it needs to be started from the root directory containing the Java package.
Problem solved! Thanks again Roel, appreciate the help.