0

My code refers to an interface and stub in the servlet's own directory(At the top, in 'WEB-INF/classes'. Stubs are created during the RMI compilation, and I can view them being present in the same folder where the servlet resides. However, when running the servlet, the stubs cannot be referred. I am starting the registry from inside the servlet itself.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("test3");
    try {
        try {
            LocateRegistry.createRegistry(5002);

            TestController obj = new TestController();
            Naming.rebind("CerberusServer", obj);
        } catch(Exception e) {
            System.out.println("EXCEPTION::::: New Servlet2:: 2:: " + e);
            System.out.println(e.getMessage());
        }
    } catch(Exception e) {
        System.out.println("unable to run RMI: " + e);
    }
}

Test Controller:

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


public class TestController extends UnicastRemoteObject implements ITestController {

protected TestController() throws RemoteException {
}

@Override
public String test(String text) throws RemoteException, Exception {
    return text;
 }
}

ITestController:

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface ITestController extends Remote {
    String test(String text) throws RemoteException, Exception;

}

The exact exception that I get when trying to bind is

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: TestController_Stub (no security manager: RMI class loader disabled)

Edit: It is different from running rmi server, classnotfound because this error is coming in a Tomcat servlet application. Without the servlet part, this error does not appear.

goluhaque
  • 561
  • 5
  • 17
  • It is the same problem with the same solution. – user207421 Nov 13 '15 at 19:07
  • Problem is indeed the fact that rmi can't find the specified class because it is not in the classpath, but the solution is different because I have tried to set the classpath to Tomcat web root, classes folder in WEB-INF etc., and it still does not work. I read somewhere that tomcat handles classpath differently, and although I don't that it could be the correct solution, I modified the shared.loader property to include all possible class folders to catalina.properties. – goluhaque Nov 14 '15 at 06:19
  • When I was not using a servlet, I added the actual class location to the classpath and everything was working perfectly. Now, not so much. – goluhaque Nov 14 '15 at 06:20
  • The CLASSPATH of a servlet consists of WEB-INF/classes and the JARs in WEB-INF/lib, plus the jars in Tomcats own lib directory. You can't change it. But you can put the required classes in any of those places. – user207421 Nov 14 '15 at 22:37
  • Tried setting the temporary CLASSPATH(via command prompt) to the WEB-INF/classes folder and then started rmiregistry. Still doesn't work. – goluhaque Nov 15 '15 at 04:58

0 Answers0