How can my servlet class which subclasses GenericServlet/HttpServlet provide an RMI service?

Mikael Jakobsson

Instead of letting your service subclass the java.rmi.server.UnicastRemoteObject class it is possible to make a call to the static method in the same class: exportObject(Remote). Thus you should let your class subclass GenericServlet/HttpServlet and implement a Remote interface. In the init(ServletContext) method your instance can export itself.
A simple example follows (exception handling omitted) :

public class MyServlet extends HttpServlet implements MyRemoteInterface {
public void init(ServletContext ctx) { UnicastRemoteObject.exportObject(this); } // rest of code goes here... }
Good luck!